From patchwork Wed Jul 3 16:07:38 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 2818001 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 307769F3C3 for ; Wed, 3 Jul 2013 16:08:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 87E7420208 for ; Wed, 3 Jul 2013 16:07:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7263220206 for ; Wed, 3 Jul 2013 16:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932979Ab3GCQHy (ORCPT ); Wed, 3 Jul 2013 12:07:54 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:61986 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932369Ab3GCQHw (ORCPT ); Wed, 3 Jul 2013 12:07:52 -0400 Received: by mail-pa0-f53.google.com with SMTP id tj12so384229pac.12 for ; Wed, 03 Jul 2013 09:07:52 -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:x-mailer:in-reply-to:references; bh=YQxuHYlG7+YE19fU66lla9HcPc0MUgocVKAbu7UvgMM=; b=hwYHDtPdr2JGkjrbEG0rc2QBE+eWovP2X8pN7HOYHcNEPy/PLASoChkLTn0COOp8wx b2leKPPdWKwRDoWcnLIQJOx38sWEu0XXlSjKeLmIBkmEMTr6eAmqW3RAMI/5wAihlZm8 jbux7KIdd0tvhFmOYfFtN705CHXb59Bi9wpj0hmxi9jKC972X6TqzUeEkwMVhUls6QGw KGqwXCDBwUHtZEQuZhloQPnPCPkaZj7CbTTxZMwwT4EuWeJKpLzHDymWE1IUYuW6ez9I JgzeaYv5r/13MlsnJZe6pg8GscWAzViCOCL9nVFMAiZqDEU7xHvYS5/A8iFQ/abw3Dfp tQ/Q== X-Received: by 10.67.5.168 with SMTP id cn8mr3114935pad.119.1372867672532; Wed, 03 Jul 2013 09:07:52 -0700 (PDT) Received: from localhost.localdomain.localdomain ([112.2.81.93]) by mx.google.com with ESMTPSA id qv4sm32120051pbc.16.2013.07.03.09.07.50 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Jul 2013 09:07:52 -0700 (PDT) From: Wang Shilong To: linux-btrfs@vger.kernel.org Cc: wangsl-fnst@cn.fujitsu.com Subject: [PATCH 2/2] Btrfs-progs: fix possible memory leak related to subvolume/snapshot creation Date: Thu, 4 Jul 2013 00:07:38 +0800 Message-Id: <1372867658-4144-2-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1372867658-4144-1-git-send-email-wangshilong1991@gmail.com> References: <1372867658-4144-1-git-send-email-wangshilong1991@gmail.com> 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 From: Wang Shilong The operation related qgroup inherit may fails, if it fails, we should free memory allocated,otherwise, memory leak happens. Signed-off-by: Wang Shilong --- cmds-subvolume.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/cmds-subvolume.c b/cmds-subvolume.c index ccb4762..9db989e 100644 --- a/cmds-subvolume.c +++ b/cmds-subvolume.c @@ -89,13 +89,17 @@ static int cmd_subvol_create(int argc, char **argv) switch (c) { case 'c': res = qgroup_inherit_add_copy(&inherit, optarg, 0); - if (res) - return res; + if (res) { + retval = res; + goto out; + } break; case 'i': res = qgroup_inherit_add_group(&inherit, optarg); - if (res) - return res; + if (res) { + retval = res; + goto out; + } break; default: usage(cmd_subvol_create_usage); @@ -516,21 +520,27 @@ static int cmd_snapshot(int argc, char **argv) switch (c) { case 'c': res = qgroup_inherit_add_copy(&inherit, optarg, 0); - if (res) - return res; + if (res) { + retval = res; + goto out; + } break; case 'i': res = qgroup_inherit_add_group(&inherit, optarg); - if (res) - return res; + if (res) { + retval = res; + goto out; + } break; case 'r': readonly = 1; break; case 'x': res = qgroup_inherit_add_copy(&inherit, optarg, 1); - if (res) - return res; + if (res) { + retval = res; + goto out; + } break; default: usage(cmd_snapshot_usage);