]> git.ipfire.org Git - pakfire.git/commitdiff
package: Keep a reference to the context
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 12:20:29 +0000 (12:20 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 12:20:29 +0000 (12:20 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/package.c

index 0c12e253e156ec776d348b6c29344bdc7941e6e2..56528d7a1c48041abecdd913b13f9488557f5536 100644 (file)
@@ -34,6 +34,7 @@
 
 #include <pakfire/archive.h>
 #include <pakfire/constants.h>
+#include <pakfire/ctx.h>
 #include <pakfire/dependencies.h>
 #include <pakfire/digest.h>
 #include <pakfire/file.h>
@@ -50,6 +51,7 @@
 #include <pakfire/util.h>
 
 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);
 }