This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFA] target.c/read_whatever_is_readable: fix memory leak


2011-02-27  Michael Snyder  <msnyder@vmware.com>

	* target.c (read_whatever_is_readable): Fix memory leak.

Index: target.c
===================================================================
RCS file: /cvs/src/src/gdb/target.c,v
retrieving revision 1.275
diff -u -p -u -p -r1.275 target.c
--- target.c	15 Feb 2011 17:22:21 -0000	1.275
+++ target.c	27 Feb 2011 23:27:16 -0000
@@ -1954,7 +1954,7 @@ read_whatever_is_readable (struct target
 			   ULONGEST begin, ULONGEST end,
 			   VEC(memory_read_result_s) **result)
 {
-  gdb_byte *buf = xmalloc (end-begin);
+  gdb_byte *buf = xmalloc (end - begin);
   ULONGEST current_begin = begin;
   ULONGEST current_end = end;
   int forward;
@@ -1962,7 +1962,10 @@ read_whatever_is_readable (struct target
 
   /* If we previously failed to read 1 byte, nothing can be done here.  */
   if (end - begin <= 1)
-    return;
+    {
+      xfree (buf);
+      return;
+    }
 
   /* Check that either first or the last byte is readable, and give up
      if not.  This heuristic is meant to permit reading accessible memory
@@ -1981,6 +1984,7 @@ read_whatever_is_readable (struct target
     }
   else
     {
+      xfree (buf);
       return;
     }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]