]> git.ipfire.org Git - pakfire.git/commitdiff
linter: Put less pressure on the reference counter
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Jan 2025 15:53:17 +0000 (15:53 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 2 Jan 2025 15:53:17 +0000 (15:53 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/linter-file.c

index b611fdcca56f18dcbc698f57f8974a8ec6a926e1..b775f41d5bc555e20214853293103bd7a0e4eee4 100644 (file)
@@ -83,6 +83,30 @@ static int pakfire_linter_file_map(struct pakfire_linter_file* lfile) {
        return 0;
 }
 
+static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
+       int r;
+
+       if (lfile->elf)
+               pakfire_elf_unref(lfile->elf);
+
+       if (lfile->data) {
+               r = munmap(lfile->data, lfile->length);
+               if (r < 0)
+                       ERROR(lfile->ctx, "Could not unmmap %s: %m\n", lfile->path);
+       }
+
+       if (lfile->fd >= 0)
+               close(lfile->fd);
+
+       if (lfile->linter)
+               pakfire_linter_unref(lfile->linter);
+       if (lfile->file)
+               pakfire_file_unref(lfile->file);
+       if (lfile->ctx)
+               pakfire_ctx_unref(lfile->ctx);
+       free(lfile);
+}
+
 int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
                struct pakfire_ctx* ctx, struct pakfire_linter* linter, struct pakfire_file* file, int fd) {
        struct pakfire_linter_file* l = NULL;
@@ -146,38 +170,15 @@ int pakfire_linter_file_create(struct pakfire_linter_file** lfile,
        }
 
        // Return the pointer
-       *lfile = pakfire_linter_file_ref(l);
+       *lfile = l;
+       return 0;
 
 ERROR:
-       if (l)
-               pakfire_linter_file_unref(l);
+       pakfire_linter_file_free(l);
 
        return r;
 }
 
-static void pakfire_linter_file_free(struct pakfire_linter_file* lfile) {
-       int r;
-
-       if (lfile->elf)
-               pakfire_elf_unref(lfile->elf);
-
-       if (lfile->data) {
-               r = munmap(lfile->data, lfile->length);
-               if (r < 0)
-                       ERROR(lfile->ctx, "Could not unmmap %s: %m\n", lfile->path);
-       }
-
-       if (lfile->fd >= 0)
-               close(lfile->fd);
-
-       if (lfile->linter)
-               pakfire_linter_unref(lfile->linter);
-       if (lfile->file)
-               pakfire_file_unref(lfile->file);
-       if (lfile->ctx)
-               pakfire_ctx_unref(lfile->ctx);
-       free(lfile);
-}
 
 struct pakfire_linter_file* pakfire_linter_file_ref(struct pakfire_linter_file* lfile) {
        ++lfile->nrefs;