Linux-f2fs-devel Archive on lore.kernel.org
 help / color / Atom feed
* [f2fs-dev] [PATCH] f2fs: fix memory leak in build_directory
@ 2019-07-31  3:27 Xiaojun Wang
  2019-07-31 10:24 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaojun Wang @ 2019-07-31  3:27 UTC (permalink / raw)
  To: linux-fsdevel, linux-f2fs-devel

This patch fix bug that variable dentries going
out of scope leaks the storage it points to.

Signed-off-by: Xiaojun Wang<wangxiaojun11@huawei.com>
---
 fsck/sload.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fsck/sload.c b/fsck/sload.c
index f5a4651..e5de2e1 100644
--- a/fsck/sload.c
+++ b/fsck/sload.c
@@ -240,15 +240,18 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
 		ret = set_selinux_xattr(sbi, dentries[i].path,
 					dentries[i].ino, dentries[i].mode);
 		if (ret)
-			return ret;
+			goto out;
+	}
 
+out:
+	for (i = 0; i < entries; i++) {
 		free(dentries[i].path);
 		free(dentries[i].full_path);
 		free((void *)dentries[i].name);
 	}
 
 	free(dentries);
-	return 0;
+	return ret;
 }
 
 static int configure_files(void)
-- 
2.7.4



_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

* Re: [f2fs-dev] [PATCH] f2fs: fix memory leak in build_directory
  2019-07-31  3:27 [f2fs-dev] [PATCH] f2fs: fix memory leak in build_directory Xiaojun Wang
@ 2019-07-31 10:24 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2019-07-31 10:24 UTC (permalink / raw)
  To: Xiaojun Wang, linux-f2fs-devel

On 2019/7/31 11:27, Xiaojun Wang wrote:
> This patch fix bug that variable dentries going
> out of scope leaks the storage it points to.

Normally, we use title like "sload.f2fs: xxx" to indicate this is a patch of
f2fs-tools, otherwise it looks like a kernel one.

It's local filesystem change, so we'd better get rid of fsdevel mailing list
submission to avoid in-there folks' complaint which has happened previously...

So just f2fs mailing list is okay. For f2fs change in kernel side,
scripts/get_maintainer.pl can indicate which list we should send to or cc. :)

> 
> Signed-off-by: Xiaojun Wang<wangxiaojun11@huawei.com>
> ---
>  fsck/sload.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/fsck/sload.c b/fsck/sload.c
> index f5a4651..e5de2e1 100644
> --- a/fsck/sload.c
> +++ b/fsck/sload.c
> @@ -240,15 +240,18 @@ static int build_directory(struct f2fs_sb_info *sbi, const char *full_path,
>  		ret = set_selinux_xattr(sbi, dentries[i].path,
>  					dentries[i].ino, dentries[i].mode);
>  		if (ret)
> -			return ret;
> +			goto out;
> +	}
>  
> +out:
I'd like to suggest to release each entry in the end of cycle to save memory in
time, and in error path, we can traverse and release dentries[i, entries]. How
do you think?

Thanks,

> +	for (i = 0; i < entries; i++) {
>  		free(dentries[i].path);
>  		free(dentries[i].full_path);
>  		free((void *)dentries[i].name);
>  	}
>  
>  	free(dentries);
> -	return 0;
> +	return ret;
>  }
>  
>  static int configure_files(void)
> 


_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel

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

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-31  3:27 [f2fs-dev] [PATCH] f2fs: fix memory leak in build_directory Xiaojun Wang
2019-07-31 10:24 ` Chao Yu

Linux-f2fs-devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-f2fs-devel/0 linux-f2fs-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-f2fs-devel linux-f2fs-devel/ https://lore.kernel.org/linux-f2fs-devel \
		linux-f2fs-devel@lists.sourceforge.net linux-f2fs-devel@archiver.kernel.org
	public-inbox-index linux-f2fs-devel


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/net.sourceforge.lists.linux-f2fs-devel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox