This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[RFC] Fix memory leak for BFD_IN_MEMORY objects
- From: dje at google dot com (Doug Evans)
- To: binutils at sourceware dot org
- Date: Thu, 23 Jul 2009 23:46:06 -0700 (PDT)
- Subject: [RFC] Fix memory leak for BFD_IN_MEMORY objects
Hi.
It seems BFD_IN_MEMORY objects leak a bit of memory because
bfd_close doesn't free bfd_in_memory or the memory buffer.
Appended is a simple patch, but I gather the intended direction
is to provide a bfd_iovec for BFD_IN_MEMORY objects.
I'll send a first pass at that in a subsequent message.
Is adding a bfd_iovec still the intended fix?
Or should this be added at least until that's decided?
2009-07-23 Doug Evans <dje@google.com>
* opncls.c (bfd_close): Until BFD_IN_MEMORY has an iovec,
at least don't leak memory.
Index: opncls.c
===================================================================
RCS file: /cvs/src/src/bfd/opncls.c,v
retrieving revision 1.55
diff -u -p -r1.55 opncls.c
--- opncls.c 12 Jun 2009 12:04:19 -0000 1.55
+++ opncls.c 23 Jul 2009 22:32:12 -0000
@@ -703,12 +703,18 @@ bfd_close (bfd *abfd)
if (! BFD_SEND (abfd, _close_and_cleanup, (abfd)))
return FALSE;
- /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
- vector. */
- if (!(abfd->flags & BFD_IN_MEMORY))
- ret = abfd->iovec->bclose (abfd);
+ if ((abfd->flags & BFD_IN_MEMORY) != 0)
+ {
+ /* FIXME: cagney/2004-02-15: Need to implement a BFD_IN_MEMORY io
+ vector.
+ Until that's done, at least don't leak memory. */
+ struct bfd_in_memory *bim = abfd->iostream;
+ free (bim->buffer);
+ free (bim);
+ ret = TRUE;
+ }
else
- ret = TRUE;
+ ret = abfd->iovec->bclose (abfd);
if (ret)
_maybe_make_executable (abfd);