From patchwork Sun Nov 4 16:55:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 30022 Received: (qmail 54349 invoked by alias); 4 Nov 2018 16:55:22 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 54339 invoked by uid 89); 4 Nov 2018 16:55:21 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.8 required=5.0 tests=AWL, 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=transferring, mainc, UD:main.c, main.c X-HELO: mailsec114.isp.belgacom.be Received: from mailsec114.isp.belgacom.be (HELO mailsec114.isp.belgacom.be) (195.238.20.110) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Nov 2018 16:55:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1541350518; x=1572886518; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=Rsraj8Ebpy/85YOJBb0CCO3FABLnI0L+VuaN4aGAa+M=; b=XqO5z2bDhhUYryw4ZYSWFqkXnuhCw5VQOTEn2Ay6bnq8YExqSbHrALFV sgGxm8Qo0aGrnkshi0zpN3QtSLJIyg==; Received: from 110.212-243-81.adsl-dyn.isp.belgacom.be (HELO md.home) ([81.243.212.110]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 04 Nov 2018 17:55:16 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA] Fix 4K leak in open_source_file each time next/step changes of function. Date: Sun, 4 Nov 2018 17:55:07 +0100 Message-Id: <20181104165507.24341-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes When current function changes after a next/step, GDB shows a message such as: (gdb) s info_fun1 () at /bd/home/philippe/gdb/git/build_smallthing/gdb/testsuite/../../../smallthing/gdb/testsuite/gdb.base/info_qt.c:41 41 info_qt_inc++; (gdb) Valgrind reports a 4K definite leak for each such message (full stacktrace of the leak below). This patch fixes this leak, by transferring the current s->fullname to the unique_xmalloc_ptr fullname given to find_and_open_source. Note that I do not understand why find_and_open_source always tries to re-execute the substitution rules on the provided fullname, as source.c symtab_to_fullname just blindly returns a non NULL s->fullname, counting on forget_cached_source_info to be called if search dir or substitution rules are changed. Similarly, psymtab_to_fullname also just returns a non NULL ps->fullname. ==15309== VALGRIND_GDB_ERROR_BEGIN ==15309== 69,632 bytes in 17 blocks are definitely lost in loss record 3,158 of 3,186 ==15309== at 0x4C2BE2D: malloc (vg_replace_malloc.c:299) ==15309== by 0x5BF0987: realpath@@GLIBC_2.3 (canonicalize.c:78) ==15309== by 0x41F713: gdb_realpath(char const*) (pathstuff.c:72) ==15309== by 0x608833: openp(char const*, enum_flags, char const*, int, std::unique_ptr >*) (source.c:861) ==15309== by 0x608B89: find_and_open_source(char const*, char const*, std::unique_ptr >*) (source.c:1049) ==15309== by 0x608D0B: open_source_file(symtab*) (source.c:1074) ==15309== by 0x609101: print_source_lines_base(symtab*, int, int, enum_flags) (source.c:1291) ==15309== by 0x614ADF: print_frame_info(frame_info*, int, print_what, int, int) (stack.c:911) ==15309== by 0x614C45: print_stack_frame(frame_info*, int, print_what, int) (stack.c:181) ==15309== by 0x511D5E: print_stop_location (infrun.c:8044) ==15309== by 0x511D5E: print_stop_event(ui_out*) (infrun.c:8061) ==15309== by 0x40DD6D: cli_on_normal_stop(bpstats*, int) (cli-interp.c:145) ==15309== by 0x512409: operator() (functional:2127) ==15309== by 0x512409: notify (observable.h:106) ==15309== by 0x512409: normal_stop() (infrun.c:8334) ==15309== by 0x5156D8: fetch_inferior_event(void*) (infrun.c:3955) ==15309== by 0x4B3EEC: gdb_wait_for_event(int) (event-loop.c:859) ==15309== by 0x4B3FF6: gdb_do_one_event() [clone .part.4] (event-loop.c:322) ==15309== by 0x4B41B4: gdb_do_one_event (common-exceptions.h:219) ==15309== by 0x4B41B4: start_event_loop() (event-loop.c:371) ==15309== by 0x551217: captured_command_loop() (main.c:330) ==15309== by 0x55220C: captured_main (main.c:1177) ==15309== by 0x55220C: gdb_main(captured_main_args*) (main.c:1193) ==15309== by 0x29B4F7: main (gdb.c:32) ==15309== ==15309== VALGRIND_GDB_ERROR_END gdb/ChangeLog 2018-11-04 Philippe Waroquiers * source.c (open_source_file): Fix leak by transferring the current s->fullname to the unique_xmalloc_ptr fullname given to find_and_open_source. --- gdb/source.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/source.c b/gdb/source.c index ec0ea3b81e..3cdf0b9ec7 100644 --- a/gdb/source.c +++ b/gdb/source.c @@ -1070,7 +1070,8 @@ open_source_file (struct symtab *s) if (!s) return -1; - gdb::unique_xmalloc_ptr fullname; + gdb::unique_xmalloc_ptr fullname (s->fullname); + s->fullname = NULL; int fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s), &fullname); s->fullname = fullname.release (); return fd;