btrfs-progs: verify_space_cache: Fix memory leak.
diff mbox

Message ID 12213854.o0zn9z9jeG@localhost.localdomain
State Under Review, archived
Headers show

Commit Message

Chandan Rajendra Sept. 22, 2013, 12:31 p.m. UTC
Free btrfs_path structure before returning due to failure of calls to
btrfs_search_slot() or btrfs_next_leaf() functions.

Signed-off-by: chandan <chandan@linux.vnet.ibm.com>
---
 cmds-check.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Patch
diff mbox

diff --git a/cmds-check.c b/cmds-check.c
index e08b79d..c947156 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -3227,14 +3227,19 @@  static int verify_space_cache(struct btrfs_root *root,
 	key.type = BTRFS_EXTENT_ITEM_KEY;
 
 	ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
-	if (ret < 0)
+	if (ret < 0) {
+		btrfs_free_path(path);
 		return ret;
+	}
+
 	ret = 0;
 	while (1) {
 		if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
 			ret = btrfs_next_leaf(root, path);
-			if (ret < 0)
+			if (ret < 0) {
+				btrfs_free_path(path);
 				return ret;
+			}
 			if (ret > 0) {
 				ret = 0;
 				break;