From: H.J. Lu Date: Tue, 9 Apr 2024 23:02:48 +0000 (-0700) Subject: mmap: Fix a memory leak in _bfd_mmap_read_temporary X-Git-Tag: gdb-15-branchpoint~436 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=533da9536e6e4d65f0623ede93365f7229779f54;p=thirdparty%2Fbinutils-gdb.git 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 --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; }