public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFA] ar.c (map_over_members): Plug memory leak.
@ 2011-03-08 20:26 Michael Snyder
  2011-03-15 11:42 ` Richard Sandiford
  0 siblings, 1 reply; 4+ messages in thread
From: Michael Snyder @ 2011-03-08 20:26 UTC (permalink / raw)
  To: binutils

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

OK?


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

2011-03-08  Michael Snyder  <msnyder@vmware.com>

	* ar.c (map_over_members): Plug memory leak.

Index: ar.c
===================================================================
RCS file: /cvs/src/src/binutils/ar.c,v
retrieving revision 1.72
diff -u -p -r1.72 ar.c
--- ar.c	8 Dec 2010 05:05:30 -0000	1.72
+++ ar.c	8 Mar 2011 20:24:33 -0000
@@ -199,9 +199,10 @@ map_over_members (bfd *arch, void (*func
       match_count = 0;
       for (head = arch->archive_next; head; head = head->archive_next)
 	{
-	  const char * filename;
+	  const char * filename = NULL;
 
 	  PROGRESS (1);
+	  free (filename);
 	  filename = head->filename;
 	  if (filename == NULL)
 	    {
@@ -237,6 +238,7 @@ map_over_members (bfd *arch, void (*func
 	/* xgettext:c-format */
 	fprintf (stderr, _("no entry %s in archive\n"), *files);
     }
+  free (filename);
 }
 \f
 bfd_boolean operation_alters_arch = FALSE;

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] ar.c (map_over_members): Plug memory leak.
  2011-03-08 20:26 [RFA] ar.c (map_over_members): Plug memory leak Michael Snyder
@ 2011-03-15 11:42 ` Richard Sandiford
  2011-03-15 11:45   ` Olaf van der Spek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Sandiford @ 2011-03-15 11:42 UTC (permalink / raw)
  To: Michael Snyder; +Cc: binutils

Michael Snyder <msnyder@vmware.com> writes:
> OK?
>
> 2011-03-08  Michael Snyder  <msnyder@vmware.com>
>
> 	* ar.c (map_over_members): Plug memory leak.
>
> Index: ar.c
> ===================================================================
> RCS file: /cvs/src/src/binutils/ar.c,v
> retrieving revision 1.72
> diff -u -p -r1.72 ar.c
> --- ar.c	8 Dec 2010 05:05:30 -0000	1.72
> +++ ar.c	8 Mar 2011 20:24:33 -0000
> @@ -199,9 +199,10 @@ map_over_members (bfd *arch, void (*func
>        match_count = 0;
>        for (head = arch->archive_next; head; head = head->archive_next)
>  	{
> -	  const char * filename;
> +	  const char * filename = NULL;
>  
>  	  PROGRESS (1);
> +	  free (filename);
>  	  filename = head->filename;
>  	  if (filename == NULL)
>  	    {
> @@ -237,6 +238,7 @@ map_over_members (bfd *arch, void (*func
>  	/* xgettext:c-format */
>  	fprintf (stderr, _("no entry %s in archive\n"), *files);
>      }
> +  free (filename);
>  }
>  \f
>  bfd_boolean operation_alters_arch = FALSE;

Maybe I'm being dense, but I don't get this.  Does it even compile?

Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] ar.c (map_over_members): Plug memory leak.
  2011-03-15 11:42 ` Richard Sandiford
@ 2011-03-15 11:45   ` Olaf van der Spek
  2011-03-15 11:59     ` Richard Sandiford
  0 siblings, 1 reply; 4+ messages in thread
From: Olaf van der Spek @ 2011-03-15 11:45 UTC (permalink / raw)
  To: Michael Snyder, binutils, richard.sandiford

On Tue, Mar 15, 2011 at 12:41 PM, Richard Sandiford
<richard.sandiford@linaro.org> wrote:
> Maybe I'm being dense, but I don't get this.  Does it even compile?

Why would it not compile?


-- 
Olaf

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [RFA] ar.c (map_over_members): Plug memory leak.
  2011-03-15 11:45   ` Olaf van der Spek
@ 2011-03-15 11:59     ` Richard Sandiford
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Sandiford @ 2011-03-15 11:59 UTC (permalink / raw)
  To: Olaf van der Spek; +Cc: Michael Snyder, binutils

Olaf van der Spek <olafvdspek@gmail.com> writes:
> On Tue, Mar 15, 2011 at 12:41 PM, Richard Sandiford
> <richard.sandiford@linaro.org> wrote:
>> Maybe I'm being dense, but I don't get this.  Does it even compile?
>
> Why would it not compile?

Because the final "free (filename);" is in the outermost block of the
function, but the "filename" variable is declared within a nested loop.

Richard

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-15 11:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 20:26 [RFA] ar.c (map_over_members): Plug memory leak Michael Snyder
2011-03-15 11:42 ` Richard Sandiford
2011-03-15 11:45   ` Olaf van der Spek
2011-03-15 11:59     ` Richard Sandiford

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).