linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gu Jinxiang <gujx@cn.fujitsu.com>
To: <linux-btrfs@vger.kernel.org>
Cc: Gu JinXiang <gujx@cn.fujitsu.com>
Subject: [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
Date: Thu, 28 Sep 2017 14:20:48 +0800	[thread overview]
Message-ID: <1506579648-60414-1-git-send-email-gujx@cn.fujitsu.com> (raw)
In-Reply-To: <1506418111-26620-1-git-send-email-gujx@cn.fujitsu.com>

From: Gu JinXiang <gujx@cn.fujitsu.com>

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 <gujx@cn.fujitsu.com>
---
 cmds-qgroup.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/cmds-qgroup.c b/cmds-qgroup.c
index 38382ea9..51d4f3a1 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) {
@@ -399,13 +398,21 @@ static int cmd_qgroup_show(int argc, char **argv)
 					qgroupid);
 	}
 	ret = btrfs_show_qgroups(fd, filter_set, comparer_set);
-	if (ret == -ENOENT)
+	if (ret == -ENOENT) {
 		error("can't list qgroups: quotas not enabled");
-	else if (ret < 0)
+		goto out;
+	} else if (ret < 0) {
 		error("can't list qgroups: %s", strerror(-ret));
+		goto out;
+	}
 	close_file_or_dir(fd, dirstream);
 
+	return !!ret;
+
 out:
+	close_file_or_dir(fd, dirstream);
+	free(filter_set);
+	free(comparer_set);
 	return !!ret;
 }
 
-- 
2.14.1




      parent reply	other threads:[~2017-09-28  6:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-26  9:28 [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled Gu Jinxiang
2017-09-26 11:27 ` David Sterba
2017-09-28  6:24   ` Gu, Jinxiang
2017-09-28  6:20 ` Gu Jinxiang [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1506579648-60414-1-git-send-email-gujx@cn.fujitsu.com \
    --to=gujx@cn.fujitsu.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).