Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: gdb-patches@sourceware.org
Cc: Philippe Waroquiers <philippe.waroquiers@skynet.be>
Subject: [RFA] Fix leak in most gdb.mi tests.
Date: Sat, 29 Dec 2018 17:01:00 -0000	[thread overview]
Message-ID: <20181229170116.8588-1-philippe.waroquiers@skynet.be> (raw)

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


             reply	other threads:[~2018-12-29 17:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-29 17:01 Philippe Waroquiers [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181229170116.8588-1-philippe.waroquiers@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox