From patchwork Mon Oct 19 11:37:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eryu Guan X-Patchwork-Id: 7435151 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C903D9F36A for ; Mon, 19 Oct 2015 11:39:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E889520748 for ; Mon, 19 Oct 2015 11:39:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0C24120739 for ; Mon, 19 Oct 2015 11:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752007AbbJSLjJ (ORCPT ); Mon, 19 Oct 2015 07:39:09 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:36817 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751063AbbJSLjI (ORCPT ); Mon, 19 Oct 2015 07:39:08 -0400 Received: by pacfv9 with SMTP id fv9so93540216pac.3 for ; Mon, 19 Oct 2015 04:39:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=WuO2xVtBwS6Rvfc5i7Jpttur07BznAyOS8/cAy+ymFk=; b=D1kGbo+bD1VKCEurzXpzPLn2HhMxNP3s6RYj+oSo7LEIwKD5ArCFHQ+Fqg0xeNTWK+ mBQmBKSGvil2AlcsysqbE+V4AixeqsyisNcHKNqyz7cBbXuqJkOBS+aO0rIHH/BwUpes AVrhgM08Or9y0/KcTDK7RBCvzmCxbLOvnMVmrpr67Q3gfyjGj1VFU3C20w8afUso9fvL devKf9vK6c0zz2btrbQKhbKtsloSomHLaLpiXjaLbXDpIcUv6EOQ8KGy6ID1bgkGofAb mYd8wtL5iZ7zBeIdoyVJSivhza2LTsbQ2az5AlWlXGtsZbxkatH8CCF+D9PmDjaP6Kwb 1zoA== X-Received: by 10.69.1.5 with SMTP id bc5mr34119561pbd.151.1445254748373; Mon, 19 Oct 2015 04:39:08 -0700 (PDT) Received: from localhost ([128.199.137.77]) by smtp.gmail.com with ESMTPSA id fk8sm36308675pab.33.2015.10.19.04.39.07 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2015 04:39:07 -0700 (PDT) From: Eryu Guan To: linux-btrfs@vger.kernel.org Cc: Eryu Guan Subject: [PATCH 01/10] btrfs-progs: fix leak of "path" in btrfs_find_item() error paths Date: Mon, 19 Oct 2015 19:37:50 +0800 Message-Id: <1445254680-11102-1-git-send-email-guaneryu@gmail.com> X-Mailer: git-send-email 2.4.3 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP path needs to be freed before return. Signed-off-by: Eryu Guan --- ctree.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/ctree.c b/ctree.c index e6e5689..1434007 100644 --- a/ctree.c +++ b/ctree.c @@ -1058,26 +1058,28 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path, path = found_path; ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0); - if ((ret < 0) || (found_key == NULL)) { - if (path != found_path) - btrfs_free_path(path); - return ret; - } + if ((ret < 0) || (found_key == NULL)) + goto out; eb = path->nodes[0]; if (ret && path->slots[0] >= btrfs_header_nritems(eb)) { ret = btrfs_next_leaf(fs_root, path); if (ret) - return ret; + goto out; eb = path->nodes[0]; } btrfs_item_key_to_cpu(eb, found_key, path->slots[0]); if (found_key->type != key.type || - found_key->objectid != key.objectid) - return 1; + found_key->objectid != key.objectid) { + ret = 1; + goto out; + } - return 0; +out: + if (path != found_path) + btrfs_free_path(path); + return ret; } /*