* [binutils-gdb] mmap: Fix a memory leak in _bfd_mmap_read_temporary
@ 2024-04-11 2:52 H.J. Lu
0 siblings, 0 replies; only message in thread
From: H.J. Lu @ 2024-04-11 2:52 UTC (permalink / raw)
To: binutils-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=533da9536e6e4d65f0623ede93365f7229779f54
commit 533da9536e6e4d65f0623ede93365f7229779f54
Author: H.J. Lu <hjl.tools@gmail.com>
Date: Tue Apr 9 16:02:48 2024 -0700
mmap: Fix a memory leak in _bfd_mmap_read_temporary
Return malloced memory in *mmap_base so that _bfd_munmap_readonly_temporary
will free it.
* libbfd.c (_bfd_mmap_read_temporary): Return malloced memory
in *mmap_base.
Diff:
---
bfd/libbfd.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/bfd/libbfd.c b/bfd/libbfd.c
index e92ed5e18a2..2f5ddcaf3b8 100644
--- a/bfd/libbfd.c
+++ b/bfd/libbfd.c
@@ -1223,8 +1223,12 @@ _bfd_mmap_read_temporary (void **data_p, size_t *size_p,
if (data == NULL)
return false;
*data_p = data;
+ /* NB: _bfd_munmap_readonly_temporary will free *MMAP_BASE if
+ *SIZE_P == 0. */
+ *mmap_base = data;
}
- *mmap_base = NULL;
+ else
+ *mmap_base = NULL;
*size_p = 0;
return bfd_read (data, size, abfd) == size;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-04-11 2:52 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-11 2:52 [binutils-gdb] mmap: Fix a memory leak in _bfd_mmap_read_temporary H.J. Lu
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).