cli-script: use unique_ptr to not leak next struct
authorAlexandra Hájková <ahajkova@redhat.com>
Thu, 20 May 2021 18:55:35 +0000 (20:55 +0200)
committerAlexandra Hájková <ahajkova@redhat.com>
Thu, 20 May 2021 19:03:47 +0000 (21:03 +0200)
commitbb6203bf1db908741de9355a6ae6969324e381d8
tree23cf6d55b4b3d7f5fb5a391991e52b7b2e69a029
parent9a01ec4c0368048fb5ea1ba1b3af9afbd651b529
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/ChangeLog
gdb/cli/cli-script.c
gdb/cli/cli-script.h