Skip to contentSkip to conversation

Btrfs-progs: free path if we don't find root item

PATCH In review Rakesh Pandit 2 participants 2 messages Feb 28, 2014 – Mar 3, 2014 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs-progs: free path if we don't find root item

In btrfs_find_last_root before returning with -ENOENT (if root item is not found) free path and also remove btrfs_release_path before btrfs_free_path because btrfs_free_path anyway calls it.

---
 root-tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
root-tree.c +3 -3
index 858fe2f..f16f0ba 100644
@@ -40,8 +40,10 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
 	ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
 	if (ret < 0)
 		goto out;
-	if (path->slots[0] == 0)
+	if (path->slots[0] == 0) {
+		btrfs_free_path(path);
 		return -ENOENT;
+	}
 
 	BUG_ON(ret == 0);
 	l = path->nodes[0];
@@ -56,7 +58,6 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
 	memcpy(key, &found_key, sizeof(found_key));
 	ret = 0;
 out:
-	btrfs_release_path(path);
 	btrfs_free_path(path);
 	return ret;
 }
@@ -120,7 +121,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 	write_extent_buffer(l, item, ptr, sizeof(*item));
 	btrfs_mark_buffer_dirty(path->nodes[0]);
 out:
-	btrfs_release_path(path);
 	btrfs_free_path(path);
 	return ret;
 }
Signature · 1 line
1.8.5.3
#1 lore raw
Quoted 14 lines · Rakesh Pandit

In btrfs_find_last_root before returning with -ENOENT (if root item is not found) free path and also remove btrfs_release_path before btrfs_free_path because btrfs_free_path anyway calls it.

---
 root-tree.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
root-tree.c +0 -0
index 858fe2f..f16f0ba 100644

root-tree.c int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, · line 44

Quoted 6 lines
root-tree.c +2 -1
@@ -40,8 +40,10 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
 	ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
 	if (ret < 0)
 		goto out;
-	if (path->slots[0] == 0)
+	if (path->slots[0] == 0) {
+		btrfs_free_path(path);

I'll change it to

		ret = -ENOENT;
		goto out;

that's the pattern commonly used.

Quoted 21 lines
root-tree.c +1 -2
 		return -ENOENT;
+	}
 
 	BUG_ON(ret == 0);
 	l = path->nodes[0];
@@ -56,7 +58,6 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
 	memcpy(key, &found_key, sizeof(found_key));
 	ret = 0;
 out:
-	btrfs_release_path(path);
 	btrfs_free_path(path);
 	return ret;
 }
@@ -120,7 +121,6 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
 	write_extent_buffer(l, item, ptr, sizeof(*item));
 	btrfs_mark_buffer_dirty(path->nodes[0]);
 out:
-	btrfs_release_path(path);
 	btrfs_free_path(path);
 	return ret;
 }