libpkgconf: cache: refactor the way package objects are marked as cached to avoid memory leaks (#133)

pull/144/head
William Pitcock 2017-09-13 14:41:00 -05:00
parent 048deb95b3
commit 9b55fc3c23
2 changed files with 6 additions and 2 deletions

View File

@ -84,6 +84,9 @@ pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
pkgconf_node_insert(&pkg->cache_iter, pkg, &client->pkg_cache);
PKGCONF_TRACE(client, "added @%p to cache", pkg);
/* mark package as cached */
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
}
/*
@ -103,6 +106,9 @@ pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg)
if (pkg == NULL)
return;
if (!(pkg->flags & PKGCONF_PKG_PROPF_CACHED))
return;
PKGCONF_TRACE(client, "removed @%p from cache", pkg);
pkgconf_node_delete(&pkg->cache_iter, &client->pkg_cache);

View File

@ -688,8 +688,6 @@ pkgconf_pkg_find(pkgconf_client_t *client, const char *name)
if ((pkg = pkgconf_cache_lookup(client, name)) != NULL)
{
PKGCONF_TRACE(client, "%s is cached", name);
pkg->flags |= PKGCONF_PKG_PROPF_CACHED;
return pkg;
}
}