[PATCH] mmap: Fix a memory leak in _bfd_mmap_read_temporary
H.J. Lu
hjl.tools@gmail.com
Tue Apr 9 23:02:48 GMT 2024
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
More information about the Binutils
mailing list