cache: use pkgconf_cache_remove to empty the cache

Which ensures that memory handling is done correctly.
Dylan Baker 2022-08-02 11:52:44 -07:00
parent 62608dfe02
commit dbc8d248c7
1 changed files with 5 additions and 18 deletions

View File

@ -214,25 +214,12 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
void void
pkgconf_cache_free(pkgconf_client_t *client) pkgconf_cache_free(pkgconf_client_t *client)
{ {
pkgconf_pkg_t **cache_table; if (client->cache_table == NULL)
size_t i, count; PKGCONF_TRACE(client, "cache is empty, not clearing");
return;
cache_table = pkgconf_reallocarray(NULL, client->cache_count, sizeof (void *)); while (client->cache_count > 0)
memcpy(cache_table, client->cache_table, pkgconf_cache_remove(client, client->cache_table[0]);
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);
PKGCONF_TRACE(client, "cleared package cache"); PKGCONF_TRACE(client, "cleared package cache");
} }