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