From: Michael Tremer Date: Wed, 24 Aug 2022 08:59:15 +0000 (+0000) Subject: filelist: Fix leaking archive entries X-Git-Tag: 0.9.28~383 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b57bb4b9f3483a0caa7a2eff4d9d53372cbfb6c;p=pakfire.git filelist: Fix leaking archive entries Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/filelist.c b/src/libpakfire/filelist.c index 8fc743617..637eae648 100644 --- a/src/libpakfire/filelist.c +++ b/src/libpakfire/filelist.c @@ -216,6 +216,10 @@ static int pakfire_filelist_is_excluded(const char* path, const char** excludes) int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, const char** includes, const char** excludes) { + struct pakfire_file* file = NULL; + struct archive_entry* entry = NULL; + int r = 1; + DEBUG(list->pakfire, "Scanning %s...\n", root); if (includes) { @@ -236,7 +240,10 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, if (!reader) return 1; - int r = 1; + // Allocate a new file entry + entry = archive_entry_new(); + if (!entry) + goto ERROR; char* paths[] = { (char*)root, NULL, @@ -280,9 +287,8 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, DEBUG(list->pakfire, "Processing %s...\n", path); - struct archive_entry* entry = archive_entry_new(); - if (!entry) - goto ERROR; + // Reset the file entry + entry = archive_entry_clear(entry); // Set path archive_entry_set_pathname(entry, path); @@ -290,6 +296,7 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, // Set source path archive_entry_copy_sourcepath(entry, node->fts_path); + // Read all file attributes from disk r = archive_read_disk_entry_from_file(reader, entry, -1, node->fts_statp); if (r) { ERROR(list->pakfire, "Could not read from %s: %m\n", node->fts_path); @@ -297,18 +304,10 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, } // Create file - struct pakfire_file* file; - r = pakfire_file_create(&file, list->pakfire); + r = pakfire_file_create_from_archive_entry(&file, list->pakfire, entry); if (r) goto ERROR; - // Import attributes - r = pakfire_file_copy_archive_entry(file, entry); - if (r) { - pakfire_file_unref(file); - goto ERROR; - } - // Append it to the list r = pakfire_filelist_append(list, file); if (r) { @@ -323,6 +322,8 @@ int pakfire_filelist_scan(struct pakfire_filelist* list, const char* root, r = 0; ERROR: + if (entry) + archive_entry_free(entry); archive_read_free(reader); return r;