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@sjtu.edu.cn>
Reviewed-by: Gao Xiang <hsiangkao@linux.alibaba.com>
Link: https://lore.kernel.org/r/20231104065041.129680-1-zhaoyifan@sjtu.edu.cn
Signed-off-by: Gao Xiang <hsiangkao@linux.alibaba.com>
void erofs_exit_configure(void)
{
+ int i;
+
#ifdef HAVE_LIBSELINUX
if (cfg.sehnd)
selabel_close(cfg.sehnd);
#endif
if (cfg.c_img_path)
free(cfg.c_img_path);
+ if (cfg.c_src_path)
+ free(cfg.c_src_path);
+ for (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 */