From: Michael Tremer Date: Fri, 8 Sep 2023 14:55:26 +0000 (+0000) Subject: file: Fix potential memory leak if entry couldn't be copied X-Git-Tag: 0.9.29~19 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a03246e0d486ff852f6fbbd8b5f0fa0d291cfbc8;p=pakfire.git file: Fix potential memory leak if entry couldn't be copied Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/file.c b/src/libpakfire/file.c index dafe2b2ac..72ba3a872 100644 --- a/src/libpakfire/file.c +++ b/src/libpakfire/file.c @@ -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) {