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"); }