All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
@ 2017-09-26  9:28 Gu Jinxiang
  2017-09-26 11:27 ` David Sterba
  2017-09-28  6:20 ` Gu Jinxiang
  0 siblings, 2 replies; 4+ messages in thread
From: Gu Jinxiang @ 2017-09-26  9:28 UTC (permalink / raw)
  To: linux-btrfs

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 | 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;
 }
 
-- 
2.14.1




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
  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
  1 sibling, 1 reply; 4+ messages in thread
From: David Sterba @ 2017-09-26 11:27 UTC (permalink / raw)
  To: Gu Jinxiang; +Cc: linux-btrfs

On Tue, Sep 26, 2017 at 05:28:31PM +0800, Gu Jinxiang wrote:
> 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>

Applied, thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
  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:20 ` Gu Jinxiang
  1 sibling, 0 replies; 4+ messages in thread
From: Gu Jinxiang @ 2017-09-28  6:20 UTC (permalink / raw)
  To: linux-btrfs; +Cc: Gu JinXiang

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




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
  2017-09-26 11:27 ` David Sterba
@ 2017-09-28  6:24   ` Gu, Jinxiang
  0 siblings, 0 replies; 4+ messages in thread
From: Gu, Jinxiang @ 2017-09-28  6:24 UTC (permalink / raw)
  To: dsterba; +Cc: linux-btrfs

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="gb2312", Size: 913 bytes --]

Hi,
I am so sorry for that this patch brings a new problem of double free in normal scenes.
So I send a new patch .
Please revert this one and use the new patch.


> -----Original Message-----
> From: David Sterba [mailto:dsterba@suse.cz]
> Sent: Tuesday, September 26, 2017 7:28 PM
> To: Gu, Jinxiang/¹Ë ½ðÏã <gujx@cn.fujitsu.com>
> Cc: linux-btrfs@vger.kernel.org
> Subject: Re: [PATCH] btrfs-progs: Resolve memory-leak in btrfs qgroup show when quota disabled
> 
> On Tue, Sep 26, 2017 at 05:28:31PM +0800, Gu Jinxiang wrote:
> > 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>
> 
> Applied, thanks.
> 



ÿôèº{.nÇ+‰·Ÿ®‰­†+%ŠËÿ±éݶ\x17¥Šwÿº{.nÇ+‰·¥Š{±ý»k~ÏâžØ^n‡r¡ö¦zË\x1aëh™¨è­Ú&£ûàz¿äz¹Þ—ú+€Ê+zf£¢·hšˆ§~†­†Ûiÿÿïêÿ‘êçz_è®\x0fæj:+v‰¨þ)ߣøm

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-09-28  6:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.