From 3e705244fc52dd77faa3027530c60d9355c85796 Mon Sep 17 00:00:00 2001 From: Ahmad Fatoum Date: Mon, 5 Sep 2022 11:55:38 +0200 Subject: commands: tutorial: fix memory leak We don't need to duplicate argv[i], because it persists for the lifetime of print_tutorial_step. We can thus drop the strdup and while at it, just drop the redundant step variable altogether. Signed-off-by: Ahmad Fatoum Link: https://lore.barebox.org/20220905095557.596891-14-a.fatoum@pengutronix.de Signed-off-by: Sascha Hauer --- commands/tutorial.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'commands') diff --git a/commands/tutorial.c b/commands/tutorial.c index 4441777643..afe5b66f0b 100644 --- a/commands/tutorial.c +++ b/commands/tutorial.c @@ -84,7 +84,6 @@ out: static int do_tutorial_next(int argc, char *argv[]) { int opt, i; - char *step = NULL; char *oldcwd; ssize_t ret = 0; bool is_prev = *argv[0] == 'p'; @@ -121,14 +120,12 @@ static int do_tutorial_next(int argc, char *argv[]) next_step = next_step > 0 ? next_step - 1 : 0; if (optind == argc) { - step = steps.gl_pathv[next_step]; - ret = print_tutorial_step(step); + ret = print_tutorial_step(steps.gl_pathv[next_step]); if (ret == 0 && !is_prev) next_step = (next_step + 1) % steps.gl_pathc; } else { for (i = optind; i < argc; i++) { - step = strdup(argv[i]); - ret = print_tutorial_step(step); + ret = print_tutorial_step(argv[i]); if (ret) break; } -- cgit v1.2.1