Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Subject: [RFA] target.c/read_whatever_is_readable: fix memory leak
Date: Sun, 27 Feb 2011 23:50:00 -0000	[thread overview]
Message-ID: <4D6ADE45.5040705@vmware.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 0 bytes --]



[-- Attachment #2: read_whatever.txt --]
[-- Type: text/plain, Size: 1194 bytes --]

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;
     }
 

             reply	other threads:[~2011-02-27 23:29 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27 23:50 Michael Snyder [this message]
2011-03-07 20:16 ` Michael Snyder
2011-03-08  5:13 ` Joel Brobecker
2011-03-08 19:39   ` Michael Snyder

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=4D6ADE45.5040705@vmware.com \
    --to=msnyder@vmware.com \
    --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