Compare commits

...

5 Commits

Author SHA1 Message Date
Dylan Baker 116e367525 main: unref another pkg 2022-08-02 11:59:55 -07:00
Dylan Baker dbc8d248c7 cache: use pkgconf_cache_remove to empty the cache
Which ensures that memory handling is done correctly.
2022-08-02 11:59:46 -07:00
Dylan Baker 62608dfe02 queue: don't flatten nothing
If after removing duplicates there are no deps to flatten, return early.
2022-08-02 11:51:59 -07:00
Dylan Baker 02710ffdef cache: if the cache_table is NULL don't search it 2022-08-02 11:51:37 -07:00
Dylan Baker 9d82962160 fixup! cache: set the cache_table to NULL if empty 2022-08-02 11:51:29 -07:00
3 changed files with 25 additions and 22 deletions

View File

@ -1162,7 +1162,7 @@ main(int argc, char *argv[])
if (required_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1195,12 +1195,14 @@ main(int argc, char *argv[])
ret = EXIT_FAILURE;
cleanup:
if (pkg)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}
else if (required_exact_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1233,12 +1235,14 @@ cleanup:
ret = EXIT_FAILURE;
cleanup2:
if (pkg)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}
else if (required_max_module_version != NULL)
{
pkgconf_pkg_t *pkg;
pkgconf_pkg_t *pkg = NULL;
pkgconf_node_t *node;
pkgconf_list_t deplist = PKGCONF_LIST_INITIALIZER;
@ -1271,6 +1275,8 @@ cleanup2:
ret = EXIT_FAILURE;
cleanup3:
if (pkg)
pkgconf_pkg_unref(&pkg_client, pkg);
pkgconf_dependency_free(&deplist);
goto out;
}

View File

@ -86,6 +86,9 @@ cache_dump(const pkgconf_client_t *client)
pkgconf_pkg_t *
pkgconf_cache_lookup(pkgconf_client_t *client, const char *id)
{
if (client->cache_table == NULL)
return NULL;
pkgconf_pkg_t **pkg;
pkg = bsearch(id, client->cache_table,
@ -186,11 +189,15 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
}
client->cache_count--;
if (client->cache_count == 0)
if (client->cache_count == 0) {
free(client->cache_table);
client->cache_table = NULL;
}
else
{
client->cache_table = pkgconf_reallocarray(client->cache_table,
client->cache_count, sizeof(void *));
}
}
/*
@ -207,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");
}

View File

@ -204,6 +204,9 @@ next:
pkgconf_pkg_unref(client, pkg);
}
if (deps == NULL)
return;
qsort(deps, dep_count, sizeof (void *), dep_sort_cmp);
/* zero the list and start readding */