]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Don't leak `entry` in `file_to_archive` if archive_read_disk_entry_from_file 843/head
authorNgie Cooper <yanegomi@gmail.com>
Tue, 13 Dec 2016 03:32:32 +0000 (19:32 -0800)
committerNgie Cooper <yanegomi@gmail.com>
Tue, 13 Dec 2016 03:39:11 +0000 (19:39 -0800)
fails with `ARCHIVE_FAILED`

This greatly reduces memory usage when the call fails, e.g. a file cannot be
stat'ed

Confirmed with the following snippet:

% d=/tmp/cpio_test
% mkdir -p $d
% while : ; do echo /nonexistent ; done | cpio -dump $d 2>/dev/null

Reported by: Coverity
CID: 1016757

cpio/cpio.c

index 373e6da787f5fc803925c04a732190bd4c1b8f69..6c20ee68322e280224a78d0127c7ec776659135e 100644 (file)
@@ -703,6 +703,7 @@ file_to_archive(struct cpio *cpio, const char *srcpath)
                lafe_warnc(0, "%s",
                    archive_error_string(cpio->archive_read_disk));
        if (r <= ARCHIVE_FAILED) {
+               archive_entry_free(entry);
                cpio->return_value = 1;
                return (r);
        }