[PATCH] erofs-utils: mkfs: fix potential memory leak
Yifan Zhao
zhaoyifan at sjtu.edu.cn
Sat Nov 4 17:50:41 AEDT 2023
Valgrind reports 2 potential memory leaks in mkfs:
Command: mkfs.erofs -zlz4 test.img testdir/
4 bytes in 1 blocks are still reachable in loss record 1 of 2
at 0x4841848: malloc (vg_replace_malloc.c:431)
by 0x49633DE: strdup (strdup.c:42)
by 0x10C483: mkfs_parse_compress_algs (main.c:287)
by 0x10C483: mkfs_parse_options_cfg (main.c:316)
by 0x10C483: main (main.c:936)
34 bytes in 1 blocks are still reachable in loss record 2 of 2
at 0x4841848: malloc (vg_replace_malloc.c:431)
by 0x49633DE: strdup (strdup.c:42)
by 0x48FFE2B: realpath_stk (canonicalize.c:409)
by 0x48FFE2B: realpath@@GLIBC_2.3 (canonicalize.c:431)
by 0x10B7EB: mkfs_parse_options_cfg (main.c:587)
by 0x10B7EB: main (main.c:936)
Fix it by freeing the memory allocated by strdup() and realpath().
Signed-off-by: Yifan Zhao <zhaoyifan at sjtu.edu.cn>
---
lib/config.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/lib/config.c b/lib/config.c
index a3235c8..2ad0122 100644
--- a/lib/config.c
+++ b/lib/config.c
@@ -54,6 +54,10 @@ void erofs_exit_configure(void)
#endif
if (cfg.c_img_path)
free(cfg.c_img_path);
+ if (cfg.c_src_path)
+ free(cfg.c_src_path);
+ for (int i = 0; i < EROFS_MAX_COMPR_CFGS && cfg.c_compr_alg[i]; i++)
+ free(cfg.c_compr_alg[i]);
}
static unsigned int fullpath_prefix; /* root directory prefix length */
--
2.42.1
More information about the Linux-erofs
mailing list