public inbox for gdb-patches@sourceware.org
 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 4K leak in open_source_file each time next/step changes of function.
Date: Sun, 04 Nov 2018 16:55:00 -0000	[thread overview]
Message-ID: <20181104165507.24341-1-philippe.waroquiers@skynet.be> (raw)

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<openp_flag>, char const*, int, std::unique_ptr<char, gdb::xfree_deleter<char> >*) (source.c:861)
==15309==    by 0x608B89: find_and_open_source(char const*, char const*, std::unique_ptr<char, gdb::xfree_deleter<char> >*) (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<print_source_lines_flag>) (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  <philippe.waroquiers@skynet.be>

	* 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<char> fullname;
+  gdb::unique_xmalloc_ptr<char> fullname (s->fullname);
+  s->fullname = NULL;
   int fd = find_and_open_source (s->filename, SYMTAB_DIRNAME (s), &fullname);
   s->fullname = fullname.release ();
   return fd;
-- 
2.19.1

             reply	other threads:[~2018-11-04 16:55 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-04 16:55 Philippe Waroquiers [this message]
2018-11-05 20:02 ` Tom Tromey
2018-11-05 20:46   ` Philippe Waroquiers

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=20181104165507.24341-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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).