Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Philippe Waroquiers <philippe.waroquiers@skynet.be>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	Tom Tromey	<tom@tromey.com>
Subject: Re: [RFA] Fix leak in linespec.c
Date: Tue, 08 Jan 2019 23:39:00 -0000	[thread overview]
Message-ID: <2c12aba6-cafa-54e2-9b69-96d95b82d3fb@ericsson.com> (raw)
In-Reply-To: <20190108062452.3942-1-philippe.waroquiers@skynet.be>

On 2019-01-08 1:24 a.m., Philippe Waroquiers wrote:
> Valgrind reports a leak in many tests, such as:
> ==9382== 16 bytes in 1 blocks are definitely lost in loss record 236 of 3,282
> ==9382==    at 0x4C2BE6D: malloc (vg_replace_malloc.c:309)
> ==9382==    by 0x4197AF: xrealloc (common-utils.c:64)
> ==9382==    by 0x51D16A: xresizevec<linespec_canonical_name> (poison.h:170)
> ==9382==    by 0x51D16A: add_sal_to_sals(linespec_state*, std::vector<symtab_and_line, std::allocator<symtab_and_line> >*, symtab_and_line*, char const*, int) (linespec.c:1041)
> ==9382==    by 0x51E2BF: create_sals_line_offset (linespec.c:2215)
> ==9382==    by 0x51E2BF: convert_linespec_to_sals(linespec_state*, linespec*) (linespec.c:2358)
> ==9382==    by 0x521B5D: convert_explicit_location_to_sals (linespec.c:2473)
> 
> Fix leak by xfree-ing self->canonical_names in linespec_state_destructor.
> The leak probably appeared with the patch 'Remove cleanup from linespec.c',
> as there was a cleanup to xfree canonical_names before the patch.
> 
> Tested on Debian/amd64, native and under valgrind.
> 
> 2019-01-07  Philippe Waroquiers  <philippe.waroquiers@skynet.be>
> 
> 	* linespec.c (linespec_state_destructor): Free self->canonical_names.
> ---
>  gdb/linespec.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/gdb/linespec.c b/gdb/linespec.c
> index b1ab462e66..f6ef4c2c40 100644
> --- a/gdb/linespec.c
> +++ b/gdb/linespec.c
> @@ -2767,6 +2767,7 @@ static void
>  linespec_state_destructor (struct linespec_state *self)
>  {
>    htab_delete (self->addr_set);
> +  xfree (self->canonical_names);
>  }
>  
>  /* Delete a linespec parser.  */
> 

Ah, indeed.  The original code in decode_line_full looks like:

  /* Arrange for allocated canonical names to be freed.  */
  if (!result.empty ())
    {
      int i;

      make_cleanup (xfree, state->canonical_names);
      for (i = 0; i < result.size (); ++i)
	{
	  gdb_assert (state->canonical_names[i].suffix != NULL);
	  make_cleanup (xfree, state->canonical_names[i].suffix);
	}
    }

... so you are adding the equivalent of the first cleanup.

It would be nice to be able to free the suffix strings in linespec_state_destructor, the
only problem is that we don't know the size of the canonical_names array at that point.

Anyway, LGTM, thanks!

Simon

  reply	other threads:[~2019-01-08 23:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-08  6:25 Philippe Waroquiers
2019-01-08 23:39 ` Simon Marchi [this message]
2019-01-09  0:40   ` Tom Tromey
2019-01-09  3:26     ` Philippe Waroquiers
2019-01-09 23:10       ` Tom Tromey
2019-01-09  3:35   ` 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=2c12aba6-cafa-54e2-9b69-96d95b82d3fb@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=philippe.waroquiers@skynet.be \
    --cc=tom@tromey.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