From 9b55fc3c2374ef3a9f0f809212dff3e97010bedc Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Wed, 13 Sep 2017 14:41:00 -0500 Subject: [PATCH] libpkgconf: cache: refactor the way package objects are marked as cached to avoid memory leaks (#133) --- libpkgconf/cache.c | 6 ++++++ libpkgconf/pkg.c | 2 -- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/libpkgconf/cache.c b/libpkgconf/cache.c index 986eba5..21ba6ca 100644 --- a/libpkgconf/cache.c +++ b/libpkgconf/cache.c @@ -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); diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index 2779e38..73b9d50 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -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; } }