From: Alan Modra Date: Tue, 24 Oct 2023 07:07:24 +0000 (+1030) Subject: asan: _bfd_elf_slurp_version_tables memory leak X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=7ac6d0c38c365a6778a91fd37203c21561c61c4c;p=binutils-gdb.git asan: _bfd_elf_slurp_version_tables memory leak Extends commit 6136093c0d00 to handle verdefs as well as verrefs. PR 30886 * elf.c (_bfd_elf_slurp_version_tables): See free_contents for verdefs too. Use free_contents rather than elf_tdata fields. --- diff --git a/bfd/elf.c b/bfd/elf.c index b5b0c69e097..bd2a5e43551 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -9571,7 +9571,7 @@ _bfd_elf_slurp_version_tables (bfd *abfd, bool default_imported_symver) } elf_tdata (abfd)->cverrefs = i; - if (elf_tdata (abfd)->dt_verneed == NULL) + if (free_contents) free (contents); contents = NULL; } @@ -9618,6 +9618,7 @@ _bfd_elf_slurp_version_tables (bfd *abfd, bool default_imported_symver) if (contents == NULL) goto error_return_verdef; + free_contents = true; BFD_ASSERT (sizeof (Elf_External_Verdef) >= sizeof (Elf_External_Verdaux)); @@ -9767,7 +9768,7 @@ _bfd_elf_slurp_version_tables (bfd *abfd, bool default_imported_symver) ((bfd_byte *) everdef + iverdef->vd_next)); } - if (elf_tdata (abfd)->dt_verdef == NULL) + if (free_contents) free (contents); contents = NULL; }