public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] memory leak in coffgen
@ 2007-07-25 23:53 msnyder
  2007-07-26 12:54 ` Alan Modra
  0 siblings, 1 reply; 6+ messages in thread
From: msnyder @ 2007-07-25 23:53 UTC (permalink / raw)
  To: binutils

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

This one's mine (not Coverity's).  I noticed that this malloc buffer
was not getting freed even when it was not requested to be cached.


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

2007-07-25  Michael Snyder  <msnyder@svkmacdonelllnx>

	* coffgen.c (_bfd_coff_read_internal_relocs): If internal_relocs
	are not to be cached, free the temporary buffer.

Index: coffgen.c
===================================================================
RCS file: /cvs/src/src/bfd/coffgen.c,v
retrieving revision 1.59
diff -p -r1.59 coffgen.c
*** coffgen.c	12 Jul 2007 07:16:40 -0000	1.59
--- coffgen.c	25 Jul 2007 23:41:50 -0000
*************** _bfd_coff_read_internal_relocs (bfd *abf
*** 457,473 ****
        free_external = NULL;
      }
  
!   if (cache && free_internal != NULL)
      {
!       if (coff_section_data (abfd, sec) == NULL)
  	{
! 	  amt = sizeof (struct coff_section_tdata);
! 	  sec->used_by_bfd = bfd_zalloc (abfd, amt);
! 	  if (sec->used_by_bfd == NULL)
! 	    goto error_return;
! 	  coff_section_data (abfd, sec)->contents = NULL;
  	}
-       coff_section_data (abfd, sec)->relocs = free_internal;
      }
  
    return internal_relocs;
--- 457,478 ----
        free_external = NULL;
      }
  
!   if (free_internal != NULL)
      {
!       if (cache == FALSE)
! 	free (free_internal);
!       else
  	{
! 	  if (coff_section_data (abfd, sec) == NULL)
! 	    {
! 	      amt = sizeof (struct coff_section_tdata);
! 	      sec->used_by_bfd = bfd_zalloc (abfd, amt);
! 	      if (sec->used_by_bfd == NULL)
! 		goto error_return;
! 	      coff_section_data (abfd, sec)->contents = NULL;
! 	    }
! 	  coff_section_data (abfd, sec)->relocs = free_internal;
  	}
      }
  
    return internal_relocs;

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

end of thread, other threads:[~2007-07-31  3:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-25 23:53 [PATCH] memory leak in coffgen msnyder
2007-07-26 12:54 ` Alan Modra
2007-07-26 18:45   ` msnyder
2007-07-31  0:39   ` msnyder
2007-07-31  7:47     ` Alan Modra
2007-07-31 11:37       ` msnyder

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