[binutils-gdb] Re: PR31145, potential memory leak in binutils/ld
Alan Modra
amodra@sourceware.org
Tue Dec 19 22:15:15 GMT 2023
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cf86e13d8bfc2924746b8e45299aed103d090985
commit cf86e13d8bfc2924746b8e45299aed103d090985
Author: Alan Modra <amodra@gmail.com>
Date: Wed Dec 20 08:29:12 2023 +1030
Re: PR31145, potential memory leak in binutils/ld
Revert most of this patch, it isn't correct to free the BFD_IN_MEMORY
iostream in io_reinit.
PR 31145
* format.c (io_reinit): Revert last change. Comment.
* opncls.c (_bfd_delete_bfd): Likewise.
Diff:
---
bfd/format.c | 15 +++++++--------
bfd/opncls.c | 2 --
2 files changed, 7 insertions(+), 10 deletions(-)
diff --git a/bfd/format.c b/bfd/format.c
index 31aeb52861a..0790a3a2ee5 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -163,16 +163,15 @@ io_reinit (bfd *abfd, struct bfd_preserve *preserve)
if (abfd->iovec != preserve->iovec)
{
/* Handle file backed to in-memory transition. bfd_cache_close
- won't do anything unless abfd->iovec is the cache_iovec. */
+ won't do anything unless abfd->iovec is the cache_iovec.
+ Don't be tempted to call iovec->bclose here. We don't want
+ to call memory_bclose, which would free the bim. The bim
+ must be kept if bfd_check_format_matches is going to decide
+ later that the PE format needing it is in fact the correct
+ target match. */
bfd_cache_close (abfd);
abfd->iovec = preserve->iovec;
-
- if (abfd->iostream != preserve->iostream)
- {
- if ((abfd->flags & BFD_IN_MEMORY) != 0)
- free (abfd->iostream);
- abfd->iostream = preserve->iostream;
- }
+ abfd->iostream = preserve->iostream;
/* Handle in-memory to file backed transition. */
if ((abfd->flags & BFD_CLOSED_BY_CACHE) != 0
diff --git a/bfd/opncls.c b/bfd/opncls.c
index e7b39593608..32c95d6ba52 100644
--- a/bfd/opncls.c
+++ b/bfd/opncls.c
@@ -176,8 +176,6 @@ _bfd_delete_bfd (bfd *abfd)
else
free ((char *) bfd_get_filename (abfd));
- if ((abfd->flags & BFD_IN_MEMORY) != 0)
- free (abfd->iostream);
free (abfd->arelt_data);
free (abfd);
}
More information about the Binutils-cvs
mailing list