]> git.ipfire.org Git - pakfire.git/commitdiff
file: Fix potential memory leak if entry couldn't be copied
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 8 Sep 2023 14:55:26 +0000 (14:55 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 8 Sep 2023 14:58:29 +0000 (14:58 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/file.c

index dafe2b2acf159f6dfe9b85f16016a26ff39ae322..72ba3a8720ac0bc918a87dd8fdf1804bb3a8ce6c 100644 (file)
@@ -431,7 +431,7 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
        // Clone the entry
        entry = archive_entry_clone(file->entry);
        if (!entry)
-               return NULL;
+               goto ERROR;
 
        // Flags
        if (pakfire_file_has_flag(file, PAKFIRE_FILE_CONFIG)) {
@@ -449,7 +449,7 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
        // Compute any required file digests
        r = pakfire_file_compute_digests(file, digest_types);
        if (r)
-               return NULL;
+               goto ERROR;
 
        // Copy digests
 
@@ -494,7 +494,7 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
                r = pakfire_file_write_fcaps(file, &cap_data);
                if (r) {
                        ERROR(file->pakfire, "Could not export capabilities: %m\n");
-                       return NULL;
+                       goto ERROR;
                }
 
                // Store capabilities in archive entry
@@ -503,6 +503,12 @@ struct archive_entry* pakfire_file_archive_entry(struct pakfire_file* file, int
        }
 
        return entry;
+
+ERROR:
+       if (entry)
+               archive_entry_free(entry);
+
+       return NULL;
 }
 
 static void pakfire_file_free(struct pakfire_file* file) {