From patchwork Thu May 20 07:24:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 101150 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.3/8.14.3) with ESMTP id o4K7QPj0005601 for ; Thu, 20 May 2010 07:26:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754197Ab0ETH0W (ORCPT ); Thu, 20 May 2010 03:26:22 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:55643 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1754069Ab0ETH0G (ORCPT ); Thu, 20 May 2010 03:26:06 -0400 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 6D845170169; Thu, 20 May 2010 15:26:03 +0800 (CST) Received: from fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id o4K7O06g016226; Thu, 20 May 2010 15:24:01 +0800 Received: from [127.0.0.1] (unknown [10.167.141.211]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id BABEB10C0A1; Thu, 20 May 2010 15:29:38 +0800 (CST) Message-ID: <4BF4E391.4070402@cn.fujitsu.com> Date: Thu, 20 May 2010 15:24:01 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.9) Gecko/20100317 Thunderbird/3.0.4 MIME-Version: 1.0 To: Chris Mason CC: Linux Btrfs Subject: [PATCH 08/10] btrfs: fix memory leak of btrfs_new_inode() Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Thu, 20 May 2010 07:26:25 +0000 (UTC) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 5271887..1cef510 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -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); }