From: Michael Tremer Date: Fri, 20 Oct 2023 12:20:29 +0000 (+0000) Subject: package: Keep a reference to the context X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;ds=sidebyside;h=484b20773387633b564426f4e0e002eeab6794e8;p=pakfire.git package: Keep a reference to the context Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/package.c b/src/libpakfire/package.c index 0c12e253..56528d7a 100644 --- a/src/libpakfire/package.c +++ b/src/libpakfire/package.c @@ -34,6 +34,7 @@ #include #include +#include #include #include #include @@ -50,6 +51,7 @@ #include struct pakfire_package { + struct pakfire_ctx* ctx; struct pakfire* pakfire; int nrefs; @@ -160,6 +162,9 @@ int pakfire_package_create_from_solvable(struct pakfire_package** package, if (!pkg) return 1; + // Store a reference to the context + pkg->ctx = pakfire_ctx(pakfire); + pkg->pakfire = pakfire_ref(pakfire); pkg->nrefs = 1; @@ -248,8 +253,10 @@ ERROR: static void pakfire_package_free(struct pakfire_package* pkg) { if (pkg->repo) pakfire_repo_unref(pkg->repo); - - pakfire_unref(pkg->pakfire); + if (pkg->pakfire) + pakfire_unref(pkg->pakfire); + if (pkg->ctx) + pakfire_ctx_unref(pkg->ctx); free(pkg); }