From 0b2752ce6276b383a5254cd766204f81f41b6631 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Tue, 11 Nov 2025 21:33:30 -0500 Subject: [PATCH] mke2fs: fix memory leak which causes ASAN to complain Fixes: 06f50e001b7d ("mke2fs: support multiple '-E' options") Signed-off-by: Theodore Ts'o --- misc/mke2fs.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/misc/mke2fs.c b/misc/mke2fs.c index 54c0f319..dd8c53d9 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1351,6 +1351,15 @@ static errcode_t init_list(struct str_list *sl) return 0; } +static void free_strlist(char **list) +{ + int i; + + for (i=0; list[i]; i++) + free(list[i]); + free(list); +} + static errcode_t push_string(struct str_list *sl, const char *str) { char **new_list; @@ -2673,6 +2682,7 @@ profile_error: /* Get options from commandline */ for (cpp = extended_opts.list; *cpp; cpp++) parse_extended_opts(&fs_param, *cpp); + free_strlist(extended_opts.list); if (fs_param.s_rev_level == EXT2_GOOD_OLD_REV) { if (fs_features) { @@ -3764,8 +3774,6 @@ no_journal: remove_error_table(&et_ext2_error_table); remove_error_table(&et_prof_error_table); profile_release(profile); - for (i=0; fs_types[i]; i++) - free(fs_types[i]); - free(fs_types); + free_strlist(fs_types); return retval; } -- 2.47.3