public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Philippe Waroquiers <philippe.waroquiers@skynet.be>
To: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [RFA] Fix leak in forward-search
Date: Thu, 29 Nov 2018 23:05:00 -0000	[thread overview]
Message-ID: <1543532723.4149.7.camel@skynet.be> (raw)
In-Reply-To: <3cf960b8-ff82-0670-fa90-c94d78573bfe@redhat.com>

On Thu, 2018-11-29 at 15:42 +0000, Pedro Alves wrote:
> On 11/27/2018 11:33 PM, Philippe Waroquiers wrote:
> > Valgrind reports the below leak.
> > Fix the leak by using xrealloc, even for the first allocation,
> > as buf is static.
> > 
> > ==29158== 5,888 bytes in 23 blocks are definitely lost in loss record 3,028 of 3,149
> > ==29158==    at 0x4C2BE2D: malloc (vg_replace_malloc.c:299)
> > ==29158==    by 0x41B557: xmalloc (common-utils.c:44)
> > ==29158==    by 0x60B7D9: forward_search_command(char const*, int) (source.c:1563)
> > ==29158==    by 0x40BA68: cmd_func(cmd_list_element*, char const*, int) (cli-decode.c:1888)
> > ==29158==    by 0x665300: execute_command(char const*, int) (top.c:630)
> > ...
> > 
> > gdb/ChangeLog
> > 2018-11-28  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> > 
> > 	* source.c (forward_search_command): Fix leak by using
> > 	xrealloc even for the first allocation in the loop, as buf
> > 	is static.
> 
> At first sight it would seem like 'buf' was made static to avoid 
> allocating a growing buffer for each command invocation.
> 
> But then, if that were the case, then you'd want 'cursize' to be
> static as well.
> 
> The patch is OK, but I think that replacing 'buf' and all that
> manual buffer growing with a non-static gdb::def_vector<char> defined
> outside the outer loop would be even better.
Thanks for the review, I have pushed this version, but I have added in
my todo list the better fix + add a test : I found no explicit
functional test for this command + my limited time on GDB development is also
shared with analysing the remaining several hundreds tests having a definite
leak :).

Philippe


  reply	other threads:[~2018-11-29 23:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-27 23:34 Philippe Waroquiers
2018-11-29 15:42 ` Pedro Alves
2018-11-29 23:05   ` Philippe Waroquiers [this message]
2018-11-30 19:43     ` [PATCH] Merge forward-search/reverse-search, use gdb::def_vector, remove limit (Re: [RFA] Fix leak in forward-search) Pedro Alves
2018-11-30 20:42       ` Tom Tromey
2018-12-08 15:12         ` Pedro Alves
2018-12-02 16:57       ` 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=1543532723.4149.7.camel@skynet.be \
    --to=philippe.waroquiers@skynet.be \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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).