[PATCH v2-changed] erofs-utils: mount: fix memory leak in erofs_nbd_get_identifier
ChengyuZhu6
hudson at cyzhu.com
Tue Sep 9 17:40:08 AEST 2025
From: Chengyu Zhu <hudsonzhu at tencent.com>
The erofs_nbd_get_identifier() function returns dynamically allocated
memory via getline(), but the caller in erofsmount_nbd() was not
freeing this memory, causing a 120-byte memory leak.
Add proper memory cleanup by calling free(id) when the identifier
is not an error pointer.
Signed-off-by: Chengyu Zhu <hudsonzhu at tencent.com>
---
mount/main.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/mount/main.c b/mount/main.c
index b22a729..c52ac3b 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -691,6 +691,8 @@ static int erofsmount_nbd(struct erofs_nbd_source *source,
if (err)
erofs_warn("failed to turn on autoclear for nbd%d: %s",
num, erofs_strerror(err));
+ if (!IS_ERR(id))
+ free(id);
}
}
return err;
--
2.51.0
More information about the Linux-erofs
mailing list