diff mbox

[01/10] btrfs-progs: fix leak of "path" in btrfs_find_item() error paths

Message ID 1445254680-11102-1-git-send-email-guaneryu@gmail.com (mailing list archive)
State Accepted
Headers show

Commit Message

Eryu Guan Oct. 19, 2015, 11:37 a.m. UTC
path needs to be freed before return.

Signed-off-by: Eryu Guan <guaneryu@gmail.com>
---
 ctree.c | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

Comments

David Sterba Oct. 19, 2015, 2:21 p.m. UTC | #1
I've merged 1, 2 (the first one), 7, 8, 9 and 10. Please add the missing
coverity references and resend. The remaining patches seem unnecessary
but please check whether I haven't missed something.
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/ctree.c b/ctree.c
index e6e5689..1434007 100644
--- a/ctree.c
+++ b/ctree.c
@@ -1058,26 +1058,28 @@  int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path,
 		path = found_path;
 
 	ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
-	if ((ret < 0) || (found_key == NULL)) {
-		if (path != found_path)
-			btrfs_free_path(path);
-		return ret;
-	}
+	if ((ret < 0) || (found_key == NULL))
+		goto out;
 
 	eb = path->nodes[0];
 	if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
 		ret = btrfs_next_leaf(fs_root, path);
 		if (ret)
-			return ret;
+			goto out;
 		eb = path->nodes[0];
 	}
 
 	btrfs_item_key_to_cpu(eb, found_key, path->slots[0]);
 	if (found_key->type != key.type ||
-			found_key->objectid != key.objectid)
-		return 1;
+			found_key->objectid != key.objectid) {
+		ret = 1;
+		goto out;
+	}
 
-	return 0;
+out:
+	if (path != found_path)
+		btrfs_free_path(path);
+	return ret;
 }
 
 /*