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

Signed-off-by: Sandeep Dhavale <[email protected]>
---
 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

Reply via email to