Message ID | 20181229170116.8588-1-philippe.waroquiers@skynet.be |
---|---|
State | New |
Headers | show |
>>>>> "Philippe" == Philippe Waroquiers <philippe.waroquiers@skynet.be> writes:
Philippe> Fix the leak by freeing in mi_execute_command_input_handler
Philippe> the command allocated in gdb_readline_no_editing_callback.
Philippe> Tested on amd64, native and under valgrind.
Philippe> gdb/ChangeLog
Philippe> 2018-12-29 Philippe Waroquiers <philippe.waroquiers@skynet.be>
Philippe> * mi/mi-interp.c (mi_execute_command_input_handler): xfree cmd,
Philippe> allocated in gdb_readline_no_editing_callback.
Thanks.
Would you mind adding to the comment comment above struct ui::input_handler
(in top.h) to explain that input_handler takes ownership of the string?
This all seems somewhat ugly to me. Perhaps ideally the caller should
manage the memory and input_handler should take a const char *? But not
your problem, fixing the leak is enough.
This is ok with the comment tweak.
Tom
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> This all seems somewhat ugly to me. Perhaps ideally the caller should
Tom> manage the memory and input_handler should take a const char *? But not
Tom> your problem, fixing the leak is enough.
I poked at this and it isn't trivial due to gdb_readline_wrapper_line.
Maybe input_handler could accept a unique_xmalloc_ptr<char>&& instead.
That would at least clarify the ownership semantics.
Tom
diff --git a/gdb/mi/mi-interp.c b/gdb/mi/mi-interp.c index 9a317bc0ec..d2a46106a1 100644 --- a/gdb/mi/mi-interp.c +++ b/gdb/mi/mi-interp.c @@ -310,6 +310,9 @@ mi_execute_command_input_handler (char *cmd) stops. */ if (ui->prompt_state == PROMPT_NEEDED) display_mi_prompt (mi); + + /* Allocated in gdb_readline_no_editing_callback. */ + xfree (cmd); } void