From: Michael Tremer Date: Tue, 17 Oct 2023 16:46:53 +0000 (+0000) Subject: file: Keep a reference to the context X-Git-Tag: 0.9.30~1455 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8780f2ec011489ceef0e6b1946096876c494feea;p=pakfire.git file: Keep a reference to the context Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index c87d06550..73ac81610 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -35,6 +35,7 @@ #include +#include #include #include #include @@ -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); }