]> www.infradead.org Git - mtd-utils.git/commitdiff
mkfs.ubifs: Fix memleak for 'output' in error paths
authorZhihao Cheng <chengzhihao1@huawei.com>
Thu, 22 Feb 2024 12:37:40 +0000 (20:37 +0800)
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>
Wed, 25 Sep 2024 07:08:41 +0000 (09:08 +0200)
The 'output' is allocated in get_options(), don't forget to free it
in error paths, move 'output' freeing out of close_target(), which
simplifies the logic of close_target().

Fixes: 36ec51948e0ec ("Add mkfs.ubifs")
Signed-off-by: Zhihao Cheng <chengzhihao1@huawei.com>
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
ubifs-utils/mkfs.ubifs/mkfs.ubifs.c

index 453a5c76cdfbaf7a57a85691691f8be0ea811ccd..f4cb51252e72e933f1dbe81e2a67ce086a61d1c8 100644 (file)
@@ -2886,8 +2886,6 @@ static int close_target(void)
                if (close(out_fd) == -1)
                        return sys_err_msg("cannot close the target '%s'", output);
        }
-       if (output)
-               free(output);
        return 0;
 }
 
@@ -3081,6 +3079,7 @@ int main(int argc, char *argv[])
                printf("Success!\n");
 
 out:
+       free(output);
        close_ubi();
        crypto_cleanup();
        return err;