From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 36A693858039; Sun, 27 Aug 2023 04:49:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 36A693858039 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Alan Modra To: bfd-cvs@sourceware.org Subject: [binutils-gdb] Confusion in coff_object_cleanup X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 398f1ddf5e89e066aeee242ea854dcbaa8eb9539 X-Git-Newrev: 26d0081b52dc482c59abba23ca495304e698ce4b Message-Id: <20230827044921.36A693858039@sourceware.org> Date: Sun, 27 Aug 2023 04:49:21 +0000 (GMT) X-BeenThere: binutils-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 27 Aug 2023 04:49:21 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D26d0081b52dc= 482c59abba23ca495304e698ce4b commit 26d0081b52dc482c59abba23ca495304e698ce4b Author: Alan Modra Date: Sun Aug 27 12:57:16 2023 +0930 Confusion in coff_object_cleanup =20 A bfd_cleanup function needs to run when only tdata is correct for the bfd. The xvec may have changed during bfd_check_format and thus the flavour may be incorrect. The format won't have changed but checking is superfluous. (In contrast to _bfd_free_cached_info or _close_and_cleanup where we do need to check things.) =20 Not getting this correct leaked comdat_hash. =20 Also, pe_ILF_cleanup ought to call coff_object_cleanup as do all PE files. =20 * coffgen.c (coff_object_cleanup): Don't check bfd flavour or format. * peicode.h (pe_ILF_cleanup): Call coff_object_cleanup. Diff: --- bfd/coffgen.c | 19 ++++++++----------- bfd/peicode.h | 2 ++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/bfd/coffgen.c b/bfd/coffgen.c index bf9633a2b33..91667267cbc 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -284,18 +284,15 @@ make_a_section_from_file (bfd *abfd, void coff_object_cleanup (bfd *abfd) { - if (bfd_family_coff (abfd) && bfd_get_format (abfd) =3D=3D bfd_object) + struct coff_tdata *td =3D coff_data (abfd); + if (td !=3D NULL) { - struct coff_tdata *td =3D coff_data (abfd); - if (td !=3D NULL) - { - if (td->section_by_index) - htab_delete (td->section_by_index); - if (td->section_by_target_index) - htab_delete (td->section_by_target_index); - if (obj_pe (abfd) && pe_data (abfd)->comdat_hash) - htab_delete (pe_data (abfd)->comdat_hash); - } + if (td->section_by_index) + htab_delete (td->section_by_index); + if (td->section_by_target_index) + htab_delete (td->section_by_target_index); + if (obj_pe (abfd) && pe_data (abfd)->comdat_hash) + htab_delete (pe_data (abfd)->comdat_hash); } } =20 diff --git a/bfd/peicode.h b/bfd/peicode.h index 5ac6b0dc53f..e1d06606575 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -1180,6 +1180,8 @@ pe_ILF_build_a_bfd (bfd * abfd, static void pe_ILF_cleanup (bfd *abfd) { + coff_object_cleanup (abfd); + struct bfd_in_memory *bim =3D abfd->iostream; free (bim->buffer); free (bim);