From: Theodore Ts'o Date: Sat, 23 Jun 2018 01:57:40 +0000 (-0400) Subject: libext2fs: fix potential resource leak in ext2fs_file_write X-Git-Tag: v1.44.3-rc1~32 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=267ff15d446076b9274bc275cc1f61922bb5d198;p=tools%2Fe2fsprogs.git libext2fs: fix potential resource leak in ext2fs_file_write If EXT2_FLAG_SHARE_DUP is set, and ext2fs_bmap2() fails, it's possible that we will leak the allocated memory in new_block. Fixes-Coverity-Bug: 1437473 Signed-off-by: Theodore Ts'o --- diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c index a5d90a7..a0b5d97 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -467,8 +467,11 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf, bmap_flags, file->blockno, 0, &file->physblock); - if (retval) + if (retval) { + free(new_block); + new_block = NULL; goto fail; + } if (new_block) { new_block->physblock = file->physblock;