From patchwork Tue Sep 26 09:28:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Jinxiang X-Patchwork-Id: 9971571 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 43F886037F for ; Tue, 26 Sep 2017 09:29:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04E4E28641 for ; Tue, 26 Sep 2017 09:29:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC707286CD; Tue, 26 Sep 2017 09:29:02 +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 C812C28641 for ; Tue, 26 Sep 2017 09:29:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967785AbdIZJ27 (ORCPT ); Tue, 26 Sep 2017 05:28:59 -0400 Received: from mail.cn.fujitsu.com ([183.91.158.132]:63595 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S967750AbdIZJ26 (ORCPT ); Tue, 26 Sep 2017 05:28:58 -0400 X-IronPort-AV: E=Sophos;i="5.42,440,1500912000"; d="scan'208";a="28290864" Received: from localhost (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Sep 2017 17:28:57 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (unknown [10.167.33.85]) by cn.fujitsu.com (Postfix) with ESMTP id 1FBF7482CFED for ; Tue, 26 Sep 2017 17:28:53 +0800 (CST) Received: from localhost.localdomain (10.167.226.132) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.361.1; Tue, 26 Sep 2017 17:28:51 +0800 From: Gu Jinxiang To: Subject: [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled Date: Tue, 26 Sep 2017 17:28:31 +0800 Message-ID: <1506418111-26620-1-git-send-email-gujx@cn.fujitsu.com> X-Mailer: git-send-email 1.9.1 MIME-Version: 1.0 X-Originating-IP: [10.167.226.132] X-yoursite-MailScanner-ID: 1FBF7482CFED.A99FE X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: gujx@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 When quota disabled, btrfs qgroup show exit with a error message, but the allocated memory is not freed. By the way, this bug marked as issue#20 in github. Signed-off-by: Gu Jinxiang --- cmds-qgroup.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmds-qgroup.c b/cmds-qgroup.c index 38382ea9..5fbfaa17 100644 --- a/cmds-qgroup.c +++ b/cmds-qgroup.c @@ -369,9 +369,8 @@ static int cmd_qgroup_show(int argc, char **argv) path = argv[optind]; fd = btrfs_open_dir(path, &dirstream, 1); if (fd < 0) { - free(filter_set); - free(comparer_set); - return 1; + ret = 1; + goto out; } if (sync) { @@ -406,6 +405,10 @@ static int cmd_qgroup_show(int argc, char **argv) close_file_or_dir(fd, dirstream); out: + if (filter_set) + free(filter_set); + if (comparer_set) + free(comparer_set); return !!ret; }