Skip to contentSkip to conversation

btrfs: fix memory leak of btrfs_new_inode()

PATCH In review Miao Xie 1 participant 1 message May 20, 2010 Btrfs file system

lore
Share & tools
lore

Miao Xie

author
#0 lore raw

PATCH 8/10 btrfs: fix memory leak of btrfs_new_inode()

btrfs_new_inode() forgets to free path when it enters the error path.

---
 fs/btrfs/inode.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
fs/btrfs/inode.c +9 -7
index 5271887..1cef510 100644
@@ -4076,15 +4076,15 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
 	BUG_ON(!path);
 
 	inode = new_inode(root->fs_info->sb);
-	if (!inode)
-		return ERR_PTR(-ENOMEM);
+	if (!inode) {
+		ret = -ENOMEM;
+		goto alloc_inode_fail;
+	}
 
 	if (dir) {
 		ret = btrfs_set_inode_index(dir, index);
-		if (ret) {
-			iput(inode);
-			return ERR_PTR(ret);
-		}
+		if (ret)
+			goto set_index_fail;
 	}
 	/*
 	 * index_cnt is ignored for everything but a dir,
@@ -4167,8 +4167,10 @@ static struct inode *btrfs_new_inode(struct btrfs_trans_handle *trans,
 fail:
 	if (dir)
 		BTRFS_I(dir)->index_cnt--;
-	btrfs_free_path(path);
+set_index_fail:
 	iput(inode);
+alloc_inode_fail:
+	btrfs_free_path(path);
 	return ERR_PTR(ret);
 }
 
Signature · 1 line
1.6.5.2