Message ID | 20181229170116.8588-1-philippe.waroquiers@skynet.be |
---|---|
State | New, archived |
Headers |
Received: (qmail 998 invoked by alias); 29 Dec 2018 17:01:26 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: <gdb-patches.sourceware.org> List-Unsubscribe: <mailto:gdb-patches-unsubscribe-##L=##H@sourceware.org> List-Subscribe: <mailto:gdb-patches-subscribe@sourceware.org> List-Archive: <http://sourceware.org/ml/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-help@sourceware.org>, <http://sourceware.org/ml/#faqs> Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 987 invoked by uid 89); 29 Dec 2018 17:01:26 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-27.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1926, HContent-Transfer-Encoding:8bit X-HELO: mailsec110.isp.belgacom.be Received: from mailsec110.isp.belgacom.be (HELO mailsec110.isp.belgacom.be) (195.238.20.106) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 29 Dec 2018 17:01:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1546102885; x=1577638885; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=eXZGdBmxL4XJXCzFrAPmzJ9zWzyOPPRxnXrtwI3uuYg=; b=rNv4LJUlpy5MliZI/12ylBt1oCHjPuLQZCwKvCI3PVJHzpxkItcLglDL OLW3RVFnq1hY9VrvZbWwHsVBfs9hRA==; Received: from 184.205-67-87.adsl-dyn.isp.belgacom.be (HELO md.home) ([87.67.205.184]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 29 Dec 2018 18:01:23 +0100 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 18:01:16 +0100 Message-Id: <20181229170116.8588-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes |
Commit Message
Philippe Waroquiers
Dec. 29, 2018, 5:01 p.m. UTC
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(+)
Comments
>>>>> "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