diff options
author | Alexandra Hájková <ahajkova@redhat.com> | 2021-05-20 20:55:35 +0200 |
---|---|---|
committer | Alexandra Hájková <ahajkova@redhat.com> | 2021-05-20 21:03:47 +0200 |
commit | bb6203bf1db908741de9355a6ae6969324e381d8 (patch) | |
tree | 23cf6d55b4b3d7f5fb5a391991e52b7b2e69a029 /gdb/cli/cli-script.h | |
parent | 9a01ec4c0368048fb5ea1ba1b3af9afbd651b529 (diff) | |
download | gdb-bb6203bf1db908741de9355a6ae6969324e381d8.zip gdb-bb6203bf1db908741de9355a6ae6969324e381d8.tar.gz gdb-bb6203bf1db908741de9355a6ae6969324e381d8.tar.bz2 |
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.
Diffstat (limited to 'gdb/cli/cli-script.h')
-rw-r--r-- | gdb/cli/cli-script.h | 3 |
1 files changed, 3 insertions, 0 deletions
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<command_line> counted_command_line; +/* A unique_ptr specialization for command_line. */ +typedef std::unique_ptr<command_line, command_lines_deleter> command_line_up; + /* * Structure for saved commands lines (for breakpoints, defined commands, etc). */ |