From: Jan Kratochvil <jan.kratochvil@redhat.com>
To: gdb-patches@sourceware.org
Subject: [patch] Fix memory leak on bfd_close(BFD_IN_MEMORY)
Date: Tue, 01 Aug 2006 16:07:00 -0000 [thread overview]
Message-ID: <20060801160653.GA8511@host0.dyn.jankratochvil.net> (raw)
[-- 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))));
+ }
}
}
next reply other threads:[~2006-08-01 16:07 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-01 16:07 Jan Kratochvil [this message]
2006-08-08 17:49 ` Daniel Jacobowitz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20060801160653.GA8511@host0.dyn.jankratochvil.net \
--to=jan.kratochvil@redhat.com \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox