]> git.ipfire.org Git - pakfire.git/commitdiff
filelist: Fix leaking archive entries
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 08:59:15 +0000 (08:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 24 Aug 2022 08:59:15 +0000 (08:59 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/filelist.c

index 8fc74361739b177179df0f1cf2ea6f2f785ded32..637eae6481852301b159f6cab59b736641edc161 100644 (file)
@@ -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;