Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Pierre Muller <pierre.muller@ics-cnrs.unistra.fr>
Cc: gdb-patches@sourceware.org
Subject: Re: [RFA] Fix memory leak in windows_xfer_shared_libraries
Date: Thu, 13 Dec 2012 20:16:00 -0000	[thread overview]
Message-ID: <50CA3784.2030706@redhat.com> (raw)
In-Reply-To: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com>

On 12/13/2012 11:11 AM, Pierre Muller wrote:
> --- windows-nat.c       13 Nov 2012 09:46:10 -0000      1.236
> +++ windows-nat.c       13 Dec 2012 10:54:18 -0000
> @@ -2411,11 +2411,11 @@ windows_xfer_shared_libraries (struct ta
>    buf = obstack_finish (&obstack);
>    len_avail = strlen (buf);
>    if (offset >= len_avail)
> -    return 0;
> -
> -  if (len > len_avail - offset)
> +    len= 0
> +  else if (len > len_avail - offset)
>      len = len_avail - offset;
> -  memcpy (readbuf, buf + offset, len);
> +  if (len > 0)
> +    memcpy (readbuf, buf + offset, len);
> 

You can avoid the last if by writing as:

  if (offset >= len_avail)
    len = 0;
  else
    {
      if (len > len_avail - offset)
	len = len_avail - offset;
      memcpy (readbuf, buf + offset, len);
    }

I'd prefer that, but patch is okay either way.

>    obstack_free (&obstack, NULL);
>    return len;

>
>   I was also wondering if it would not be better to keep the obstack in
> between the two calls, but that would probably require some static variable
> :(

That'd be fine.  We actually do that in some cases in gdbserver, like
handle_qxfer_threads and handle_qxfer_traceframe_info.  It just didn't
look like worth it enough to bother when I initially wrote this.

-- 
Pedro Alves


       reply	other threads:[~2012-12-13 20:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-13 20:16 ` Pedro Alves [this message]
2012-12-14  7:53   ` Pierre Muller
2012-12-14 10:12     ` Pedro Alves
2012-12-14 10:26       ` [RFA] Fix other memory leak in solib_target_current_sos Pierre Muller
2012-12-14 10:55         ` Pedro Alves
2012-12-14 13:07           ` [RFA-v2] " Pierre Muller
2012-12-14 13:49             ` Pedro Alves
     [not found]       ` <43198.6185875305$1355480794@news.gmane.org>
2012-12-14 14:14         ` [RFA] " Tom Tromey
2012-12-14 23:29           ` Pierre Muller
2012-12-13 11:11 [RFA] Fix memory leak in windows_xfer_shared_libraries Pierre Muller
2012-12-13 11:23 ` Pierre Muller

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=50CA3784.2030706@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=pierre.muller@ics-cnrs.unistra.fr \
    /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