From bb6203bf1db908741de9355a6ae6969324e381d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandra=20H=C3=A1jkov=C3=A1?= Date: Thu, 20 May 2021 20:55:35 +0200 Subject: cli-script: use unique_ptr to not leak next struct In cli/cli-script.c, process_next_line() allocates memory which will eventually end up being assigned to the 'next' field in struct command_line. However, in a case recurse_read_control_structure returns 'invalid_control' this memory is leaked. This commit uses std::unique_ptr as appropriate to prevent this leakage. This issue was found by coverity scanning. gdb/ChangeLog: * cli/cli-script.h (command_line_up): New unique_ptr typedef. * cli/cli-script.c (multi_line_command_p): Use unique_ptr command_line_up instead of struct command_line. (build_command_line): Likewise. (get_command_line): Update the cmd function call parameter. (process_next_line): Use unique_ptr command_line_up instead of struct command_line. (recurse_read_control_structure): Change the the type of next to command_line_up. (read_command_lines_1): Change type of `next' to be command_line_up and update all references of `next' accordingly. --- gdb/cli/cli-script.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gdb/cli/cli-script.h') diff --git a/gdb/cli/cli-script.h b/gdb/cli/cli-script.h index 8624bf5..8c98fdd 100644 --- a/gdb/cli/cli-script.h +++ b/gdb/cli/cli-script.h @@ -66,6 +66,9 @@ struct command_lines_deleter /* A reference-counted struct command_line. */ typedef std::shared_ptr counted_command_line; +/* A unique_ptr specialization for command_line. */ +typedef std::unique_ptr command_line_up; + /* * Structure for saved commands lines (for breakpoints, defined commands, etc). */ -- cgit v1.1