]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
mmap: Fix a memory leak in _bfd_mmap_read_temporary
authorH.J. Lu <hjl.tools@gmail.com>
Tue, 9 Apr 2024 23:02:48 +0000 (16:02 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 11 Apr 2024 02:51:29 +0000 (19:51 -0700)
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

index e92ed5e18a21bcc22993a9d5c06b6518198d52dc..2f5ddcaf3b8626a34d92290e9e673f06ea4e5a23 100644 (file)
@@ -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;
 }