Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Snyder <msnyder@vmware.com>
To: Pedro Alves <pedro@codesourcery.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	 "drow@false.org" <drow@false.org>
Subject: Re: [RFA] Fix memory leak in gdbserver/hostio.c
Date: Sun, 27 Feb 2011 21:57:00 -0000	[thread overview]
Message-ID: <4D6AC713.10800@vmware.com> (raw)
In-Reply-To: <201102271705.43466.pedro@codesourcery.com>

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

Pedro Alves wrote:
> On Sunday 27 February 2011 00:30:38, Michael Snyder wrote:
>> Found by coverity.
> 
> Do you try running coverity on your patches?
> 
>> @@ -367,6 +367,7 @@ handle_pwrite (char *own_buf, int packet
>>        || require_data (p, packet_len - (p - own_buf), &data, &len))
>>      {
>>        hostio_packet_error (own_buf);
>> +      free (data);
>>        return;
>>      }
> 
> This is wrong.  If any predicate other than require_data in if above
> returned true, then you'll be freeing a garbage pointer.  I'd
> fix this in require_data ... just free the output buffer when
> returning error, so the callers never have to.

Like this?


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

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

	* hostio.c (require_data): Free malloc memory before returning
	error.

Index: hostio.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbserver/hostio.c,v
retrieving revision 1.11
diff -u -p -u -p -r1.11 hostio.c
--- hostio.c	1 Jan 2011 15:33:24 -0000	1.11
+++ hostio.c	27 Feb 2011 21:48:00 -0000
@@ -134,7 +134,10 @@ require_data (char *p, int p_len, char *
     }
 
   if (escaped)
-    return -1;
+    {
+      xfree (data);
+      return -1;
+    }
 
   *data_len = output_index;
   return 0;

  reply	other threads:[~2011-02-27 21:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-27  0:40 Michael Snyder
2011-02-27 17:10 ` Pedro Alves
2011-02-27 21:57   ` Michael Snyder [this message]
2011-02-27 23:29     ` Pedro Alves
2011-02-28  4:39     ` [commit] Compilation regression [Re: [RFA] Fix memory leak in gdbserver/hostio.c] Jan Kratochvil
2011-02-28 16:00       ` Ulrich Weigand

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=4D6AC713.10800@vmware.com \
    --to=msnyder@vmware.com \
    --cc=drow@false.org \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro@codesourcery.com \
    /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