From 7ac6d0c38c365a6778a91fd37203c21561c61c4c Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Tue, 24 Oct 2023 17:37:24 +1030 Subject: [PATCH] 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. --- bfd/elf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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; } -- 2.30.2