Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFA] Fix memory leak in windows_xfer_shared_libraries
@ 2012-12-13 11:11 Pierre Muller
  2012-12-13 11:23 ` Pierre Muller
  0 siblings, 1 reply; 5+ messages in thread
From: Pierre Muller @ 2012-12-13 11:11 UTC (permalink / raw)
  To: gdb-patches

  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;


^ permalink raw reply	[flat|nested] 5+ messages in thread
[parent not found: <50c9b7e6.25f2440a.3810.3771SMTPIN_ADDED_BROKEN@mx.google.com>]

end of thread, other threads:[~2012-12-14 10:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-13 11:11 [RFA] Fix memory leak in windows_xfer_shared_libraries Pierre Muller
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox