On 2025/9/9 14:55, ChengyuZhu6 wrote:
From: Chengyu Zhu <hudson...@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 <hudson...@tencent.com>

The subject line should be fixed from:

`erofs-utils:mount: fix memory leak in erofs_nbd_get_identifier`
             ^
to
`erofs-utils: mount: fix memory leak in erofs_nbd_get_identifier`

Otherwise it looks good to me, will apply.

Thanks,
Gao Xiang

---
  mount/main.c | 2 ++
  1 file changed, 2 insertions(+)

diff --git a/mount/main.c b/mount/main.c
index 0daf232..d4f1cda 100644
--- a/mount/main.c
+++ b/mount/main.c
@@ -741,6 +741,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;


Reply via email to