* [PATCH] mmap: Fix a memory leak in _bfd_mmap_read_temporary
@ 2024-04-09 23:02 H.J. Lu
2024-04-10 23:53 ` Alan Modra
0 siblings, 1 reply; 2+ messages in thread
From: H.J. Lu @ 2024-04-09 23:02 UTC (permalink / raw)
To: binutils
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.
---
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;
}
--
2.44.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] mmap: Fix a memory leak in _bfd_mmap_read_temporary
2024-04-09 23:02 [PATCH] mmap: Fix a memory leak in _bfd_mmap_read_temporary H.J. Lu
@ 2024-04-10 23:53 ` Alan Modra
0 siblings, 0 replies; 2+ messages in thread
From: Alan Modra @ 2024-04-10 23:53 UTC (permalink / raw)
To: H.J. Lu; +Cc: binutils
On Tue, Apr 09, 2024 at 04:02:48PM -0700, H.J. Lu wrote:
> 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.
OK, I'm assuming you know what you're doing here.
--
Alan Modra
Australia Development Lab, IBM
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-04-10 23:54 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-09 23:02 [PATCH] mmap: Fix a memory leak in _bfd_mmap_read_temporary H.J. Lu
2024-04-10 23:53 ` Alan Modra
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).