[PATCH 2/4] btrfs-progs: fsck: Fix patch allocation check and leak in check_fs_first_inode

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allocated 'path' in check_fs_first_inode() is not checked and for
btrfs_search_slot() error, it will leak 'path'.

Fix it.

Reported-by: David Sterba <dsterba@xxxxxxx>
Resolves-Coverity-CID: 1374098
Resolves-Coverity-CID: 1374099
Signed-off-by: Qu Wenruo <quwenruo@xxxxxxxxxxxxxx>
---
 cmds-check.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/cmds-check.c b/cmds-check.c
index a92901d..91ed8b4 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -4963,13 +4963,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;
@@ -4979,6 +4981,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;
 }
-- 
2.10.1



--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Filesystem Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux