linux-f2fs-devel.lists.sourceforge.net archive mirror
 help / color / mirror / Atom feed
* [f2fs-dev] [PATCH v2] fsck.f2fs: fix memleak in f2fs_create()
@ 2023-06-02 10:24 Maxim Korotkov
  2023-06-05  4:18 ` Chao Yu
  2023-06-05  4:21 ` Chao Yu
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Korotkov @ 2023-06-02 10:24 UTC (permalink / raw)
  To: Chao Yu; +Cc: Maxim Korotkov, linux-f2fs-devel

In error handling cases, the function exited without releasing memory

Signed-off-by: Maxim Korotkov <korotkov.maxim.s@gmail.com>
---
changelog: fixed code review remarks
 fsck/dir.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/fsck/dir.c b/fsck/dir.c
index 4a3eb6e..29c89de 100644
--- a/fsck/dir.c
+++ b/fsck/dir.c
@@ -704,7 +704,8 @@ 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;
+		ret = -1;
+		goto free_parent_dir;
 	}
 
 	ret = f2fs_find_entry(sbi, parent, de);
@@ -713,6 +714,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
 					de->name, de->pino, ret);
 		if (de->file_type == F2FS_FT_REG_FILE)
 			de->ino = 0;
+		ret = 0;
 		goto free_parent_dir;
 	}
 
@@ -728,7 +730,8 @@ 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;
+			ret = -1;
+			goto free_child_dir;
 		}
 
 		/* Use previously-recorded inode */
@@ -750,6 +753,7 @@ int f2fs_create(struct f2fs_sb_info *sbi, struct dentry *de)
 	if (ret) {
 		MSG(0, "Skip the existing \"%s\" pino=%x ERR=%d\n",
 					de->name, de->pino, ret);
+		ret = 0;
 		goto free_child_dir;
 	}
 
@@ -804,7 +808,7 @@ free_child_dir:
 	free(child);
 free_parent_dir:
 	free(parent);
-	return 0;
+	return ret;	
 }
 
 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] 3+ messages in thread

end of thread, other threads:[~2023-06-05  4:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-02 10:24 [f2fs-dev] [PATCH v2] fsck.f2fs: fix memleak in f2fs_create() Maxim Korotkov
2023-06-05  4:18 ` Chao Yu
2023-06-05  4:21 ` Chao Yu

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).