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

index 97c9da440fbb49747589cac6e393ddd9db564056..8fd354e6b65bdb1fc16bf93eef05056173fb8475 100644 (file)
@@ -28,6 +28,7 @@
 #include <sqlite3.h>
 
 #include <pakfire/archive.h>
+#include <pakfire/ctx.h>
 #include <pakfire/db.h>
 #include <pakfire/dependencies.h>
 #include <pakfire/digest.h>
@@ -46,6 +47,7 @@
 #define SCHEMA_MIN_SUP 7
 
 struct pakfire_db {
+       struct pakfire_ctx* ctx;
        struct pakfire* pakfire;
        int nrefs;
 
@@ -373,8 +375,10 @@ static void pakfire_db_free(struct pakfire_db* db) {
                }
        }
 
-       pakfire_unref(db->pakfire);
-
+       if (db->pakfire)
+               pakfire_unref(db->pakfire);
+       if (db->ctx)
+               pakfire_ctx_unref(db->ctx);
        free(db);
 }
 
@@ -680,6 +684,9 @@ int pakfire_db_open(struct pakfire_db** db, struct pakfire* pakfire, int flags)
        if (!o)
                return -ENOMEM;
 
+       // Store a reference to the context
+       o->ctx = pakfire_ctx(pakfire);
+
        o->pakfire = pakfire_ref(pakfire);
        o->nrefs = 1;