From dbc8d248c79e95fc32120f9d0e7b5e0c5cc6ff34 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 2 Aug 2022 11:52:44 -0700 Subject: [PATCH] cache: use pkgconf_cache_remove to empty the cache Which ensures that memory handling is done correctly. --- libpkgconf/cache.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/libpkgconf/cache.c b/libpkgconf/cache.c index dc1c342..2da69e6 100644 --- a/libpkgconf/cache.c +++ b/libpkgconf/cache.c @@ -214,25 +214,12 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg) void pkgconf_cache_free(pkgconf_client_t *client) { - pkgconf_pkg_t **cache_table; - size_t i, count; + if (client->cache_table == NULL) + PKGCONF_TRACE(client, "cache is empty, not clearing"); + return; - cache_table = pkgconf_reallocarray(NULL, client->cache_count, sizeof (void *)); - memcpy(cache_table, client->cache_table, - client->cache_count * sizeof (void *)); - - /* first we clear cached match pointers */ - for (i = 0, count = client->cache_count; i < count; i++) - { - pkgconf_pkg_t *pkg = cache_table[i]; - - pkgconf_dependency_free(&pkg->required); - pkgconf_dependency_free(&pkg->requires_private); - pkgconf_dependency_free(&pkg->provides); - pkgconf_dependency_free(&pkg->conflicts); - } - - free(cache_table); + while (client->cache_count > 0) + pkgconf_cache_remove(client, client->cache_table[0]); PKGCONF_TRACE(client, "cleared package cache"); }