From patchwork Mon Oct 24 02:43:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9391297 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EC5A6086B for ; Mon, 24 Oct 2016 02:44:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 306E828A73 for ; Mon, 24 Oct 2016 02:44:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16A9428C0F; Mon, 24 Oct 2016 02:44:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A5D3828A73 for ; Mon, 24 Oct 2016 02:44:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932321AbcJXCn5 (ORCPT ); Sun, 23 Oct 2016 22:43:57 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:39208 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932125AbcJXCn4 (ORCPT ); Sun, 23 Oct 2016 22:43:56 -0400 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="922781" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 24 Oct 2016 10:43:49 +0800 Received: from adam-work.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 2A7FF41B4BD8; Mon, 24 Oct 2016 10:43:44 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org, dsterba@suse.cz Subject: [PATCH 2/4] btrfs-progs: fsck: Fix patch allocation check and leak in check_fs_first_inode Date: Mon, 24 Oct 2016 10:43:33 +0800 Message-Id: <20161024024335.6770-2-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.1 In-Reply-To: <20161024024335.6770-1-quwenruo@cn.fujitsu.com> References: <20161024024335.6770-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 2A7FF41B4BD8.AF0F1 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Allocated 'path' in check_fs_first_inode() is not checked and for btrfs_search_slot() error, it will leak 'path'. Fix it. Reported-by: David Sterba Resolves-Coverity-CID: 1374098 Resolves-Coverity-CID: 1374099 Signed-off-by: Qu Wenruo --- cmds-check.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmds-check.c b/cmds-check.c index a92901d..91ed8b4 100644 --- a/cmds-check.c +++ b/cmds-check.c @@ -4963,13 +4963,15 @@ static int check_fs_first_inode(struct btrfs_root *root, unsigned int ext_ref) int ret; path = btrfs_alloc_path(); + if (!path) + return -ENOMEM; key.objectid = 256; key.type = BTRFS_INODE_ITEM_KEY; key.offset = 0; ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); if (ret < 0) - return ret; + goto out; if (ret > 0) { ret = 0; err |= INODE_ITEM_MISSING; @@ -4979,6 +4981,7 @@ static int check_fs_first_inode(struct btrfs_root *root, unsigned int ext_ref) err &= ~LAST_ITEM; if (err && !ret) ret = -EIO; +out: btrfs_free_path(path); return ret; }