All of lore.kernel.org
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH] fsck.f2fs: fix memleak in f2fs_create()
@ 2023-05-31  7:22 Maxim Korotkov
  2023-06-02  9:44 ` Chao Yu
  0 siblings, 1 reply; 2+ messages in thread
From: Maxim Korotkov @ 2023-05-31  7:22 UTC (permalink / raw)
  To: Jaegeuk Kim; +Cc: Maxim Korotkov, Maxim Korotkov, linux-f2fs-devel

In error handling cases, exiting a function without releasing memory
Added tags to clean up resources and return error code
Found by RASU JSC
Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
---
 fsck/dir.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index 4a3eb6e..c3508bf 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -704,7 +704,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
 	ret = convert_inline_dentry(sbi, parent, ni.blk_addr);
 	if (ret) {
 		MSG(0, "Convert inline dentry for pino=%x failed.\n", de->pino);
-		return -1;
+		goto err_free_parent_dir;
 	}
 
 	ret = f2fs_find_entry(sbi, parent, de);
@@ -728,7 +728,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
 		if (hardlink_ni.blk_addr == NULL_ADDR) {
 			MSG(1, "No original inode for hard link to_ino=%x\n",
 				found_hardlink->to_ino);
-			return -1;
+			goto err_free_child_dir;
 		}
 
 		/* Use previously-recorded inode */
@@ -805,6 +805,11 @@ free_child_dir:
 free_parent_dir:
 	free(parent);
 	return 0;
+err_free_child_dir:
+	free(child);
+err_free_parent_dir:
+	free(parent);
+	return -1;	
 }
 
 int f2fs_mkdir(struct f2fs_sb_info *sbi, struct dentry *de)
-- 
2.34.1



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

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

* Re: [f2fs-dev] [PATCH] fsck.f2fs: fix memleak in f2fs_create()
  2023-05-31  7:22 [f2fs-dev] [PATCH] fsck.f2fs: fix memleak in f2fs_create() Maxim Korotkov
@ 2023-06-02  9:44 ` Chao Yu
  0 siblings, 0 replies; 2+ messages in thread
From: Chao Yu @ 2023-06-02  9:44 UTC (permalink / raw)
  To: Maxim Korotkov, Jaegeuk Kim; +Cc: Maxim Korotkov, linux-f2fs-devel

On 2023/5/31 15:22, Maxim Korotkov wrote:
> In error handling cases, exiting a function without releasing memory
> Added tags to clean up resources and return error code
> Found by RASU JSC
> Signed-off-by: Maxim Korotkov <maskorotkov@rasu.ru>
> ---
>   fsck/dir.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/fsck/dir.c b/fsck/dir.c
> index 4a3eb6e..c3508bf 100644
> --- a/fsck/dir.c
> +++ b/fsck/dir.c
> @@ -704,7 +704,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
>   	ret = convert_inline_dentry(sbi, parent, ni.blk_addr);
>   	if (ret) {
>   		MSG(0, "Convert inline dentry for pino=%x failed.\n", de->pino);
> -		return -1;
> +		goto err_free_parent_dir;

How about:

	ret = -1
	goto free_parent_dir;

>   	}
>   
>   	ret = f2fs_find_entry(sbi, parent, de);
> @@ -728,7 +728,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
>   		if (hardlink_ni.blk_addr == NULL_ADDR) {
>   			MSG(1, "No original inode for hard link to_ino=%x\n",
>   				found_hardlink->to_ino);
> -			return -1;
> +			goto err_free_child_dir;
	ret = -1
	goto free_child_dir;

>   		}
>   
>   		/* Use previously-recorded inode */
> @@ -805,6 +805,11 @@ free_child_dir:
>   free_parent_dir:
>   	free(parent);
>   	return 0;

	return ret;

Thanks,

> +err_free_child_dir:
> +	free(child);
> +err_free_parent_dir:
> +	free(parent);
> +	return -1;	
>   }
>   
>   int f2fs_mkdir(struct f2fs_sb_info *sbi, struct dentry *de)


_______________________________________________
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, other threads:[~2023-06-02  9:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-31  7:22 [f2fs-dev] [PATCH] fsck.f2fs: fix memleak in f2fs_create() Maxim Korotkov
2023-06-02  9:44 ` Chao Yu

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.