]> git.ipfire.org Git - pakfire.git/commitdiff
file: Keep a reference to the context
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 16:46:53 +0000 (16:46 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 17 Oct 2023 16:46:53 +0000 (16:46 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index c87d06550db1cd1ec4efe0e852c64880209462f8..73ac816103c835317e36e902d0289361fca1df61 100644 (file)
@@ -35,6 +35,7 @@
 
 #include <gelf.h>
 
+#include <pakfire/ctx.h>
 #include <pakfire/constants.h>
 #include <pakfire/digest.h>
 #include <pakfire/fhs.h>
@@ -59,6 +60,7 @@ enum pakfire_file_verification_status {
 };
 
 struct pakfire_file {
+       struct pakfire_ctx* ctx;
        struct pakfire* pakfire;
        int nrefs;
 
@@ -366,6 +368,9 @@ PAKFIRE_EXPORT int pakfire_file_create(struct pakfire_file** file, struct pakfir
        if (!f)
                return 1;
 
+       // Store a reference to the context
+       f->ctx = pakfire_ctx(pakfire);
+
        // Store reference to Pakfire
        f->pakfire = pakfire_ref(pakfire);
 
@@ -517,7 +522,10 @@ static void pakfire_file_free(struct pakfire_file* file) {
                cap_free(file->caps);
        if (file->entry)
                archive_entry_free(file->entry);
-       pakfire_unref(file->pakfire);
+       if (file->pakfire)
+               pakfire_unref(file->pakfire);
+       if (file->ctx)
+               pakfire_ctx_unref(file->ctx);
        free(file);
 }