From 44b4b126f31873877f308d0f636dfd5739f14134 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 5 Dec 2017 17:32:00 -0600 Subject: [PATCH] libpkgconf: pkg: record which pkgconf_client_t owns each pkgconf_pkg_t object --- libpkgconf/cache.c | 2 +- libpkgconf/libpkgconf.h | 6 ++++-- libpkgconf/pkg.c | 13 +++++++++---- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/libpkgconf/cache.c b/libpkgconf/cache.c index 1662ce5..fa8b3b3 100644 --- a/libpkgconf/cache.c +++ b/libpkgconf/cache.c @@ -44,7 +44,7 @@ * :rtype: pkgconf_pkg_t * */ pkgconf_pkg_t * -pkgconf_cache_lookup(const pkgconf_client_t *client, const char *id) +pkgconf_cache_lookup(pkgconf_client_t *client, const char *id) { pkgconf_node_t *node; diff --git a/libpkgconf/libpkgconf.h b/libpkgconf/libpkgconf.h index ac873bf..30f52a7 100644 --- a/libpkgconf/libpkgconf.h +++ b/libpkgconf/libpkgconf.h @@ -136,6 +136,8 @@ struct pkgconf_pkg_ { pkgconf_list_t vars; unsigned int flags; + + pkgconf_client_t *owner; }; typedef bool (*pkgconf_pkg_iteration_func_t)(const pkgconf_pkg_t *pkg, void *data); @@ -242,7 +244,7 @@ PKGCONF_API bool pkgconf_default_error_handler(const char *msg, const pkgconf_cl } while (0); #endif -PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg); +PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API pkgconf_pkg_t *pkgconf_pkg_find(pkgconf_client_t *client, const char *name); @@ -306,7 +308,7 @@ PKGCONF_API bool pkgconf_queue_apply(pkgconf_client_t *client, pkgconf_list_t *l PKGCONF_API bool pkgconf_queue_validate(pkgconf_client_t *client, pkgconf_list_t *list, int maxdepth); /* cache.c */ -PKGCONF_API pkgconf_pkg_t *pkgconf_cache_lookup(const pkgconf_client_t *client, const char *id); +PKGCONF_API pkgconf_pkg_t *pkgconf_cache_lookup(pkgconf_client_t *client, const char *id); PKGCONF_API void pkgconf_cache_add(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_cache_remove(pkgconf_client_t *client, pkgconf_pkg_t *pkg); PKGCONF_API void pkgconf_cache_free(pkgconf_client_t *client); diff --git a/libpkgconf/pkg.c b/libpkgconf/pkg.c index cc1edda..f883623 100644 --- a/libpkgconf/pkg.c +++ b/libpkgconf/pkg.c @@ -475,10 +475,12 @@ pkgconf_pkg_free(pkgconf_client_t *client, pkgconf_pkg_t *pkg) * :rtype: pkgconf_pkg_t * */ pkgconf_pkg_t * -pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg) +pkgconf_pkg_ref(pkgconf_client_t *client, pkgconf_pkg_t *pkg) { - (void) client; + if (pkg->owner != NULL && pkg->owner != client) + PKGCONF_TRACE(client, "WTF: client %p refers to package %p owned by other client %p", client, pkg, pkg->owner); + pkg->owner = client; pkg->refcount++; PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount); @@ -499,11 +501,14 @@ pkgconf_pkg_ref(const pkgconf_client_t *client, pkgconf_pkg_t *pkg) void pkgconf_pkg_unref(pkgconf_client_t *client, pkgconf_pkg_t *pkg) { + if (pkg->owner != NULL && pkg->owner != client) + PKGCONF_TRACE(client, "WTF: client %p unrefs package %p owned by other client %p", client, pkg, pkg->owner); + pkg->refcount--; - PKGCONF_TRACE(client, "refcount@%p: %d", pkg, pkg->refcount); + PKGCONF_TRACE(pkg->owner, "refcount@%p: %d", pkg, pkg->refcount); if (pkg->refcount <= 0) - pkgconf_pkg_free(client, pkg); + pkgconf_pkg_free(pkg->owner, pkg); } static inline pkgconf_pkg_t *