diff options
author | Alan Modra <amodra@gmail.com> | 2025-01-12 14:33:33 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2025-01-20 07:13:46 +1030 |
commit | 354ed4d4a26da57cf2a2b9b463c4262b18c48021 (patch) | |
tree | 8856de0623ad4c2f1741214560d9df1368a9e9ab | |
parent | d4115c2c8d447e297ae353892de89192c1996211 (diff) | |
download | binutils-354ed4d4a26da57cf2a2b9b463c4262b18c48021.zip binutils-354ed4d4a26da57cf2a2b9b463c4262b18c48021.tar.gz binutils-354ed4d4a26da57cf2a2b9b463c4262b18c48021.tar.bz2 |
_bfd_elf_munmap_section_contents
Do unmap/free cached contents to avoid some memory leaks we'd
otherwise see.
* elf.c (_bfd_elf_munmap_section_contents): Clear pointers to
contents that we unmap/free rather than not unmapping/freeing.
-rw-r--r-- | bfd/elf.c | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -14270,15 +14270,15 @@ _bfd_elf_munmap_section_contents (asection *sec ATTRIBUTE_UNUSED, if (contents == NULL) return; + /* Don't leave pointers to data we are about to munmap or free. */ + if (sec->contents == contents) + sec->contents = NULL; + if (elf_section_data (sec)->this_hdr.contents == contents) + elf_section_data (sec)->this_hdr.contents = NULL; + #ifdef USE_MMAP if (sec->mmapped_p) { - /* _bfd_elf_mmap_section_contents may return the previously - mapped section contents. Munmap the section contents only - if they haven't been cached. */ - if (elf_section_data (sec)->this_hdr.contents == contents) - return; - /* When _bfd_elf_mmap_section_contents returns CONTENTS as malloced, CONTENTS_ADDR is set to NULL. */ if (elf_section_data (sec)->contents_addr != NULL) @@ -14288,7 +14288,6 @@ _bfd_elf_munmap_section_contents (asection *sec ATTRIBUTE_UNUSED, elf_section_data (sec)->contents_size) != 0) abort (); sec->mmapped_p = 0; - sec->contents = NULL; elf_section_data (sec)->contents_addr = NULL; elf_section_data (sec)->contents_size = 0; return; |