[PATCH v1 1/7] erofs-utils: fsck: Fix potential memory leak in error path

Sandeep Dhavale dhavale at google.com
Thu Sep 14 08:10:58 AEST 2023


Free the memory allocated for 'entry' if strdup() fails.

Signed-off-by: Sandeep Dhavale <dhavale at google.com>
---
 fsck/main.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fsck/main.c b/fsck/main.c
index 7f78513..3f86da4 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -585,8 +585,10 @@ static int erofsfsck_hardlink_insert(erofs_nid_t nid, const char *path)
 
 	entry->nid = nid;
 	entry->path = strdup(path);
-	if (!entry->path)
+	if (!entry->path) {
+		free(entry);
 		return -ENOMEM;
+	}
 
 	list_add_tail(&entry->list,
 		      &erofsfsck_link_hashtable[nid % NR_HARDLINK_HASHTABLE]);
-- 
2.42.0.283.g2d96d420d3-goog



More information about the Linux-erofs mailing list