From: Theodore Ts'o Date: Thu, 5 Dec 2024 03:41:20 +0000 (-0500) Subject: misc: fix potential memory leak in create_inode_libarchive.c X-Git-Tag: v1.47.2~26 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=559b5d21c082585899e48230dae4d3b37eec503e;p=thirdparty%2Fe2fsprogs.git misc: fix potential memory leak in create_inode_libarchive.c Fix a potential memory leak on an error path. Also handle the case where strdup() fails, and remove a redundant test. Addresses-Coverity-Bug: 1636564 Addresses-Coverity-Bug: 1636565 Signed-off-by: Theodore Ts'o --- diff --git a/misc/create_inode_libarchive.c b/misc/create_inode_libarchive.c index 8a0fec32..9c8e53e4 100644 --- a/misc/create_inode_libarchive.c +++ b/misc/create_inode_libarchive.c @@ -292,8 +292,6 @@ static int remove_inode(ext2_filsys fs, ext2_ino_t ino) write_out: ret = ext2fs_write_inode_full(fs, ino, (struct ext2_inode *)&inode, sizeof(inode)); - if (ret) - goto out; out: return ret; } @@ -578,7 +576,7 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, struct file_info *target, struct fs_ops_callbacks *fs_callbacks) { - char *path2, *path3, *dir, *name; + char *path2=NULL, *path3=NULL, *dir, *name; unsigned int dir_exists; struct archive *a; struct archive_entry *entry; @@ -629,6 +627,10 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, } path2 = strdup(dl_archive_entry_pathname(entry)); path3 = strdup(dl_archive_entry_pathname(entry)); + if (!path2 || !path3) { + retval = ENOMEM; + goto out; + } name = basename(path2); dir = dirname(path3); if ((retval = __find_path(fs, root_ino, dir, &dirinode))) { @@ -709,11 +711,13 @@ errcode_t __populate_fs_from_tar(ext2_filsys fs, ext2_ino_t root_ino, goto out; } - free(path2); - free(path3); + free(path2); path2 = NULL; + free(path3); path3 = NULL; } out: + free(path2); + free(path3); dl_archive_read_close(a); dl_archive_read_free(a); return retval;