Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Fix leak in most gdb.mi tests.
@ 2018-12-29 17:01 Philippe Waroquiers
  2018-12-29 19:15 ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Philippe Waroquiers @ 2018-12-29 17:01 UTC (permalink / raw)
  To: gdb-patches; +Cc: Philippe Waroquiers

Valgrind detects a leak on the input_buffer in most (all?) gdb.mi tests,
e.g. gdb.mi/mi2-var-child.exp:

  ==27567== 23,120 bytes in 313 blocks are definitely lost in loss record 3,149 of 3,200
  ==27567==    at 0x4C2E2B3: realloc (vg_replace_malloc.c:836)
  ==27567==    by 0x403D1C: xrealloc (common-utils.c:62)
  ==27567==    by 0x402DD3: buffer_grow(buffer*, char const*, unsigned long) [clone .part.1] (buffer.c:40)
  ==27567==    by 0x49CECA: buffer_grow_char (buffer.h:40)
  ==27567==    by 0x49CECA: gdb_readline_no_editing_callback(void*) (event-top.c:847)
  ==27567==    by 0x49D27F: stdin_event_handler(int, void*) (event-top.c:511)
  ==27567==    by 0x49C0CC: gdb_wait_for_event(int) (event-loop.c:859)
  ==27567==    by 0x49C203: gdb_do_one_event() [clone .part.4] (event-loop.c:347)
  ==27567==    by 0x49C394: gdb_do_one_event (common-exceptions.h:219)
  ==27567==    by 0x49C394: start_event_loop() (event-loop.c:371)
  ==27567==    by 0x532687: captured_command_loop() (main.c:330)
  ==27567==    by 0x53367C: captured_main (main.c:1177)
  ==27567==    by 0x53367C: gdb_main(captured_main_args*) (main.c:1193)
  ==27567==    by 0x2841A7: main (gdb.c:32)

Fix the leak by freeing in mi_execute_command_input_handler
the command allocated in gdb_readline_no_editing_callback.

Tested on amd64, native and under valgrind.

gdb/ChangeLog
2018-12-29  Philippe Waroquiers  <philippe.waroquiers@skynet.be>

	* mi/mi-interp.c (mi_execute_command_input_handler): xfree cmd,
	allocated in gdb_readline_no_editing_callback.
---
 gdb/mi/mi-interp.c | 3 +++
 1 file changed, 3 insertions(+)

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
-- 
2.19.2


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2018-12-30 23:43 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-29 17:01 [RFA] Fix leak in most gdb.mi tests Philippe Waroquiers
2018-12-29 19:15 ` Tom Tromey
2018-12-29 19:33   ` Tom Tromey
2018-12-29 19:44     ` Tom Tromey
2018-12-30  9:28       ` Philippe Waroquiers
2018-12-30 15:55         ` Tom Tromey
2018-12-30 21:24           ` Philippe Waroquiers
2018-12-30 23:43             ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox