* [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY)
@ 2006-08-01 16:07 Jan Kratochvil
2006-08-08 17:49 ` Daniel Jacobowitz
0 siblings, 1 reply; 2+ messages in thread
From: Jan Kratochvil @ 2006-08-01 16:07 UTC (permalink / raw)
To: gdb-patches
[-- Attachment #1: Type: text/plain, Size: 978 bytes --]
Hi,
I feel the patch
2004-10-24 Daniel Jacobowitz <dan@debian.org>
* opncls.c (bfd_close): Return TRUE for BFD_IN_MEMORY.
Index: opncls.c
===================================================================
RCS file: /cvs/src/src/bfd/opncls.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -p -r1.25 -r1.26
--- opncls.c 10 Oct 2004 13:58:05 -0000 1.25
+++ opncls.c 24 Oct 2004 18:45:38 -0000 1.26
@@ -598,7 +598,7 @@ bfd_close (bfd *abfd)
if (!(abfd->flags & BFD_IN_MEMORY))
ret = abfd->iovec->bclose (abfd);
else
- ret = 0;
+ ret = TRUE;
/* If the file was open for writing and is now executable,
make it so. */
introduced a memory leak. This codepath occurs only on ia64 on the second run:
(gdb) run
(gdb) run
Attached patch which IMO fixes the leak and it does not crash (although it was
not ElectricFence-d) on ia64.
Maybe not worth it (yes, the proper function set should be implemented etc.).
Regards,
Jan Kratochvil
[-- Attachment #2: gdb-6.5.50.20060801-bfd_close-BFD_IN_MEMORY.patch --]
[-- Type: text/plain, Size: 1531 bytes --]
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=200402
diff -ru gdb-6.3-orig/bfd/opncls.c gdb-6.3/bfd/opncls.c
--- gdb-6.3-orig/bfd/opncls.c 2006-07-28 04:56:05.000000000 -0400
+++ gdb-6.3/bfd/opncls.c 2006-07-28 04:56:25.000000000 -0400
@@ -595,27 +595,36 @@
/* 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);
- else
- ret = TRUE;
+ if (abfd->flags & BFD_IN_MEMORY)
+ {
+ struct bfd_in_memory *bim = abfd->iostream;
- /* If the file was open for writing and is now executable,
- make it so. */
- if (ret
- && abfd->direction == write_direction
- && abfd->flags & EXEC_P)
+ free (bim->buffer);
+ free (bim);
+
+ ret = TRUE;
+ }
+ else
{
- struct stat buf;
+ ret = abfd->iovec->bclose (abfd);
- if (stat (abfd->filename, &buf) == 0)
+ /* If the file was open for writing and is now executable,
+ make it so. */
+ if (ret
+ && abfd->direction == write_direction
+ && abfd->flags & EXEC_P)
{
- unsigned int mask = umask (0);
+ struct stat buf;
- umask (mask);
- chmod (abfd->filename,
- (0777
- & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
+ if (stat (abfd->filename, &buf) == 0)
+ {
+ unsigned int mask = umask (0);
+
+ umask (mask);
+ chmod (abfd->filename,
+ (0777
+ & (buf.st_mode | ((S_IXUSR | S_IXGRP | S_IXOTH) &~ mask))));
+ }
}
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY)
2006-08-01 16:07 [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY) Jan Kratochvil
@ 2006-08-08 17:49 ` Daniel Jacobowitz
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2006-08-08 17:49 UTC (permalink / raw)
To: Jan Kratochvil; +Cc: gdb-patches
On Tue, Aug 01, 2006 at 06:06:53PM +0200, Jan Kratochvil wrote:
> I feel the patch
> 2004-10-24 Daniel Jacobowitz <dan@debian.org>
>
> * opncls.c (bfd_close): Return TRUE for BFD_IN_MEMORY.
>
> introduced a memory leak. This codepath occurs only on ia64 on the second run:
Well, it was already there, I think. Anyway, the master copy of BFD
belongs to the binutils project; you should send patches for it to the
binutils@ list.
I don't think your patch is quite right since bim is not always
malloc'd. It's sometimes bfd_alloc'd. Doing that more often might be
a better solution.
--
Daniel Jacobowitz
CodeSourcery
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2006-08-08 17:49 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-08-01 16:07 [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY) Jan Kratochvil
2006-08-08 17:49 ` Daniel Jacobowitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox