Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <pierre.muller@ics-cnrs.unistra.fr>
To: <gdb-patches@sourceware.org>
Subject: [RFA] Fix memory leak in windows_xfer_shared_libraries
Date: Thu, 13 Dec 2012 11:11:00 -0000	[thread overview]
Message-ID: <008a01cdd922$971dcb00$c5596100$@muller@ics-cnrs.unistra.fr> (raw)

  The current mechanism of getting the list of DLLs when command
infl dll 
is given to gdb prompt,
info_shared_library function in solib.c calls
  windows_xfer_shared_libraries in windows-nat.c

  using target_read_stralloc, which calls target_read_alloc_1.

  That function reiterates calls to target_read_partial
until the number of transferred bytes is zero...

  This results even if the buffer is large enough to contain all data at
first
call in a second call in which the same xml answer is computed again,
and nothing is done, because the offset correspond to the end of the
resulting
string.

  The current code has a memory leak that is fixed by the patch below.

  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
:(
 

Pierre Muller
GDB pascal language maintainer


2012-12-13  Pierre Muller  <muller@sourceware.org>

        * windows-nat.c (windows_xfer_shared_libraries): Avoid
        memory leak when OFFSET >= LEN_AVAIL.

Index: windows-nat.c
===================================================================
RCS file: /cvs/src/src/gdb/windows-nat.c,v
retrieving revision 1.236
diff -u -p -r1.236 windows-nat.c
--- 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);

   obstack_free (&obstack, NULL);
   return len;


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

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-13 11:11 Pierre Muller [this message]
2012-12-13 11:23 ` Pierre Muller
     [not found] <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com>
2012-12-13 20:16 ` Pedro Alves
2012-12-14  7:53   ` Pierre Muller
2012-12-14 10:12     ` Pedro Alves

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='008a01cdd922$971dcb00$c5596100$@muller@ics-cnrs.unistra.fr' \
    --to=pierre.muller@ics-cnrs.unistra.fr \
    --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