Fix: lttng-snapshot: use after free of max size argument
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 17 May 2022 17:41:49 +0000 (13:41 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 17 May 2022 17:41:49 +0000 (13:41 -0400)
gcc 12.1.0 reports:

commands/snapshot.cpp: In function ‘int cmd_snapshot(int, const char**)’:
../../../src/common/error.hpp:139:32: error: pointer ‘max_size_arg’ may be used after ‘void free(void*)’ [-Werror=use-after-free]

free max_size_arg on both paths.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I3775e835e10b364f32f4797afb9c090ac4dc133c

src/bin/lttng/commands/snapshot.cpp

index 583714d101e347c410644a3ac654ece57bf3d68a..3cb66c5557406ed3585d80f1f4c4185cda51be9e 100644 (file)
@@ -627,16 +627,16 @@ int cmd_snapshot(int argc, const char **argv)
                        const int parse_ret = utils_parse_size_suffix(
                                        (char *) max_size_arg, &val);
 
-                       free(max_size_arg);
                        if (parse_ret < 0) {
                                ERR("Unable to handle max-size value %s",
                                                max_size_arg);
                                cmd_ret = CMD_ERROR;
+                               free(max_size_arg);
                                goto end;
                        }
 
                        opt_max_size = val;
-
+                       free(max_size_arg);
                        break;
                }
                default:
This page took 0.026047 seconds and 4 git commands to generate.