From: Qu Wenruo Date: Mon, 24 Oct 2016 02:43:33 +0000 (+0800) Subject: btrfs-progs: fsck: Fix patch allocation check and leak in check_fs_first_inode X-Git-Tag: upstream/4.16.1~942 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=45f782abf3694d4cf2b61adeccf0c8c8974fc23f;p=platform%2Fupstream%2Fbtrfs-progs.git btrfs-progs: fsck: Fix patch allocation check and leak in check_fs_first_inode Allocated 'path' in check_fs_first_inode() is not checked and for btrfs_search_slot() error, it will leak 'path'. Fix it. Resolves-Coverity-CID: 1374098 Resolves-Coverity-CID: 1374099 Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- diff --git a/cmds-check.c b/cmds-check.c index 22d3a66..d1ca679 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -4940,13 +4940,15 @@ static int check_fs_first_inode(struct btrfs_root *root, unsigned int ext_ref) int ret; path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; key.objectid = 256; key.type = BTRFS_INODE_ITEM_KEY; key.offset = 0; ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) - return ret; + goto out; if (ret > 0) { ret = 0; err |= INODE_ITEM_MISSING; @@ -4956,6 +4958,7 @@ static int check_fs_first_inode(struct btrfs_root *root, unsigned int ext_ref) err &= ~LAST_ITEM; if (err && !ret) ret = -EIO; +out: btrfs_free_path(path); return ret; }