public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [RFA] (take two): ar.c (map_over_members): Plug memory leak.
@ 2011-03-08 20:32 Michael Snyder
  2011-03-15 11:43 ` Richard Sandiford
  2011-03-15 11:52 ` Andreas Schwab
  0 siblings, 2 replies; 3+ messages in thread
From: Michael Snyder @ 2011-03-08 20:32 UTC (permalink / raw)
  To: binutils

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

Sorry for the noise.  This patch replaces the previous patch for
map_over_members.

OK?


[-- Attachment #2: ar4.txt --]
[-- Type: text/plain, Size: 1419 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:30:20 -0000
@@ -199,7 +199,7 @@ 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, * filename2 = NULL;
 
 	  PROGRESS (1);
 	  filename = head->filename;
@@ -213,11 +213,13 @@ map_over_members (bfd *arch, void (*func
 	  else if (bfd_is_thin_archive (arch))
 	    {
 	      /* Thin archives store full pathnames.  Need to normalize.  */
+	      free (filename);
 	      filename = normalize (filename, arch);
 	    }
 
-	  if (filename != NULL
-	      && !FILENAME_CMP (normalize (*files, arch), filename))
+	  free (filename2);
+	  filename2 = normalize (*files, arch);
+	  if (filename != NULL && !FILENAME_CMP (filename2, filename))
 	    {
 	      ++match_count;
 	      if (counted_name_mode
@@ -237,6 +239,8 @@ map_over_members (bfd *arch, void (*func
 	/* xgettext:c-format */
 	fprintf (stderr, _("no entry %s in archive\n"), *files);
     }
+  free (filename);
+  free (filename2);
 }
 \f
 bfd_boolean operation_alters_arch = FALSE;

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

* Re: [RFA] (take two): ar.c (map_over_members): Plug memory leak.
  2011-03-08 20:32 [RFA] (take two): ar.c (map_over_members): Plug memory leak Michael Snyder
@ 2011-03-15 11:43 ` Richard Sandiford
  2011-03-15 11:52 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Richard Sandiford @ 2011-03-15 11:43 UTC (permalink / raw)
  To: Michael Snyder; +Cc: binutils

Michael Snyder <msnyder@vmware.com> writes:
> Sorry for the noise.

Likewise, although...

> 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:30:20 -0000
> @@ -199,7 +199,7 @@ 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, * filename2 = NULL;
>  
>  	  PROGRESS (1);
>  	  filename = head->filename;
> @@ -213,11 +213,13 @@ map_over_members (bfd *arch, void (*func
>  	  else if (bfd_is_thin_archive (arch))
>  	    {
>  	      /* Thin archives store full pathnames.  Need to normalize.  */
> +	      free (filename);
>  	      filename = normalize (filename, arch);
>  	    }
>  
> -	  if (filename != NULL
> -	      && !FILENAME_CMP (normalize (*files, arch), filename))
> +	  free (filename2);
> +	  filename2 = normalize (*files, arch);
> +	  if (filename != NULL && !FILENAME_CMP (filename2, filename))
>  	    {
>  	      ++match_count;
>  	      if (counted_name_mode
> @@ -237,6 +239,8 @@ map_over_members (bfd *arch, void (*func
>  	/* xgettext:c-format */
>  	fprintf (stderr, _("no entry %s in archive\n"), *files);
>      }
> +  free (filename);
> +  free (filename2);
>  }
>  \f
>  bfd_boolean operation_alters_arch = FALSE;

...my question is the same here.  I'm surprised this compiles.

Richard

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

* Re: [RFA] (take two): ar.c (map_over_members): Plug memory leak.
  2011-03-08 20:32 [RFA] (take two): ar.c (map_over_members): Plug memory leak Michael Snyder
  2011-03-15 11:43 ` Richard Sandiford
@ 2011-03-15 11:52 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2011-03-15 11:52 UTC (permalink / raw)
  To: Michael Snyder; +Cc: binutils

Michael Snyder <msnyder@vmware.com> writes:

> @@ -213,11 +213,13 @@ map_over_members (bfd *arch, void (*func
>  	  else if (bfd_is_thin_archive (arch))
>  	    {
>  	      /* Thin archives store full pathnames.  Need to normalize.  */
> +	      free (filename);

Double free?

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-08 20:32 [RFA] (take two): ar.c (map_over_members): Plug memory leak Michael Snyder
2011-03-15 11:43 ` Richard Sandiford
2011-03-15 11:52 ` Andreas Schwab

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).