From patchwork Thu Mar 27 15:50:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Lyakas X-Patchwork-Id: 3898411 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 090F5BF540 for ; Thu, 27 Mar 2014 15:51:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 292B720237 for ; Thu, 27 Mar 2014 15:51:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 182DE20179 for ; Thu, 27 Mar 2014 15:51:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756917AbaC0PvA (ORCPT ); Thu, 27 Mar 2014 11:51:00 -0400 Received: from mail-ig0-f169.google.com ([209.85.213.169]:41271 "EHLO mail-ig0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756815AbaC0Pu6 (ORCPT ); Thu, 27 Mar 2014 11:50:58 -0400 Received: by mail-ig0-f169.google.com with SMTP id h18so1619425igc.2 for ; Thu, 27 Mar 2014 08:50:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=AmmF7Z0ozzgjSm6yBHsqmTgP0Wt7/kNcBfRy+QAVDVA=; b=FxTvNPdoeNhQgD0oCv/L1hRMJMwsipHBOXPDegMhfr3uGRrhWVaQmdLtXjSpR+ag/i cBT+s6EOW6U8rnzS4ARz8DdDD8Gdyztyv+p0kiRYeERwjOFFwOAOxv9m5HE97mAiOM5M vSdCqpOEAtRU8rEvreXGrl7LMEqIRX/QK7FFBBv8ou7/sbhJ4xPGyEIRsNfKcHer33mg ML5E0OIIiw0iP5i2G+vQ/MkDMtlbWp4IyzZfW/KYF7PgfhyEzEuk1NYPK9W4lxZLqTcz qaX9TQJgUmsvwxLql8ls4ZjuBefghg/viyrv91X0vqXZIPWowLjSbWtme38WcimLdZ+t P3hg== X-Gm-Message-State: ALoCoQnVz67+JrQ1VH48pJ1a0Z1JnadNkDAeIhkg4u3GskMR6vDARL0ClO8XYrjVTs/ThldOdL2A MIME-Version: 1.0 X-Received: by 10.50.92.102 with SMTP id cl6mr5310657igb.44.1395935457836; Thu, 27 Mar 2014 08:50:57 -0700 (PDT) Received: by 10.64.13.69 with HTTP; Thu, 27 Mar 2014 08:50:57 -0700 (PDT) In-Reply-To: <201303210432.AA00023@FM-323941448.jp.fujitsu.com> References: <201303210432.AA00023@FM-323941448.jp.fujitsu.com> Date: Thu, 27 Mar 2014 17:50:57 +0200 Message-ID: Subject: Re: [PATCH] Btrfs: fix memory leak in btrfs_create_tree() From: Alex Lyakas To: Tsutomu Itoh , Josef Bacik Cc: linux-btrfs , Filipe Manana Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, 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 Hi Tsutomu Itoh, On Thu, Mar 21, 2013 at 6:32 AM, Tsutomu Itoh wrote: > We should free leaf and root before returning from the error > handling code. > > Signed-off-by: Tsutomu Itoh > --- > fs/btrfs/disk-io.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c > index 7d84651..b1b5baa 100644 > --- a/fs/btrfs/disk-io.c > +++ b/fs/btrfs/disk-io.c > @@ -1291,6 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, > 0, objectid, NULL, 0, 0, 0); > if (IS_ERR(leaf)) { > ret = PTR_ERR(leaf); > + leaf = NULL; > goto fail; > } > > @@ -1334,11 +1335,16 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, > > btrfs_tree_unlock(leaf); > > + return root; > + > fail: > - if (ret) > - return ERR_PTR(ret); > + if (leaf) { > + btrfs_tree_unlock(leaf); > + free_extent_buffer(leaf); I believe this is not enough. Few lines above, another reference on the root is taken by root->commit_root = btrfs_root_node(root); So I believe the proper fix would be: return ERR_PTR(ret); Thanks, Alex. > + } > + kfree(root); > > - return root; > + return ERR_PTR(ret); > } > > static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans, > > -- > To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html --- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index d9698fd..260af79 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1354,10 +1354,10 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, return root; fail: - if (leaf) { + if (leaf) btrfs_tree_unlock(leaf); - free_extent_buffer(leaf); - } + free_extent_buffer(root->node); + free_extent_buffer(root->commit_root); kfree(root);