From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 76BBA385842A; Thu, 1 Jun 2023 00:33:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 76BBA385842A 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] section_by_target_index memory leak X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: d18f60c747c220ef8ca118b61e5db5c5cdf8f28b X-Git-Newrev: 90fd5049bde965ad217a013398ffc722f298de82 Message-Id: <20230601003324.76BBA385842A@sourceware.org> Date: Thu, 1 Jun 2023 00:33:24 +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: Thu, 01 Jun 2023 00:33:24 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D90fd5049bde9= 65ad217a013398ffc722f298de82 commit 90fd5049bde965ad217a013398ffc722f298de82 Author: Alan Modra Date: Tue May 30 20:05:38 2023 +0930 section_by_target_index memory leak =20 The rs6000 backend can call coff_section_from_bfd_index from its object_p function via coff_set_alignment_hook. If the object doesn't match, or another target matches too, then the hash table needs to be freed via a cleanup. =20 * coffgen.c (coff_object_cleanup): New function. (coff_real_object_p): Return coff_object_cleanup, and call on failure path. Move declaration to.. * libcoff-in.h: ..here. (coff_object_cleanup): Declare. * coff-stgo32.c (go32exe_cleanup): Call coff_object_cleanup. (go32exe_check_format): Adjust assertion. * libcoff.h: Regenerate. Diff: --- bfd/coff-stgo32.c | 3 ++- bfd/coffgen.c | 24 ++++++++++++++++++------ bfd/libcoff-in.h | 4 ++++ bfd/libcoff.h | 4 ++++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/bfd/coff-stgo32.c b/bfd/coff-stgo32.c index f443a30c7b1..707b80963da 100644 --- a/bfd/coff-stgo32.c +++ b/bfd/coff-stgo32.c @@ -248,6 +248,7 @@ static void go32exe_cleanup (bfd *abfd) { abfd->origin =3D 0; + coff_object_cleanup (abfd); =20 free (go32exe_temp_stub); go32exe_temp_stub =3D NULL; @@ -323,7 +324,7 @@ go32exe_check_format (bfd *abfd) bfd_cleanup cleanup =3D coff_object_p (abfd); if (cleanup =3D=3D NULL) goto fail; - BFD_ASSERT (cleanup =3D=3D _bfd_no_cleanup); + BFD_ASSERT (cleanup =3D=3D coff_object_cleanup); =20 return go32exe_cleanup; =20 diff --git a/bfd/coffgen.c b/bfd/coffgen.c index c81f67c1711..afc663c056f 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -281,14 +281,25 @@ make_a_section_from_file (bfd *abfd, return result; } =20 +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) + { + if (td->section_by_index) + htab_delete (td->section_by_index); + if (td->section_by_target_index) + htab_delete (td->section_by_target_index); + } + } +} + /* Read in a COFF object and make it into a BFD. This is used by ECOFF as well. */ bfd_cleanup -coff_real_object_p (bfd *, - unsigned, - struct internal_filehdr *, - struct internal_aouthdr *); -bfd_cleanup coff_real_object_p (bfd *abfd, unsigned nscns, struct internal_filehdr *internal_f, @@ -358,9 +369,10 @@ coff_real_object_p (bfd *abfd, } =20 _bfd_coff_free_symbols (abfd); - return _bfd_no_cleanup; + return coff_object_cleanup; =20 fail: + coff_object_cleanup (abfd); _bfd_coff_free_symbols (abfd); bfd_release (abfd, tdata); fail2: diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index 24a950dedd4..96f44512ac5 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -331,6 +331,10 @@ struct decoration_hash_entry }; =20 /* Functions in coffgen.c. */ +extern void coff_object_cleanup + (bfd *); +extern bfd_cleanup coff_real_object_p + (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *); extern bfd_cleanup coff_object_p (bfd *); extern struct bfd_section *coff_section_from_bfd_index diff --git a/bfd/libcoff.h b/bfd/libcoff.h index c5d15a13f7b..61561c5a471 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -335,6 +335,10 @@ struct decoration_hash_entry }; =20 /* Functions in coffgen.c. */ +extern void coff_object_cleanup + (bfd *); +extern bfd_cleanup coff_real_object_p + (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *); extern bfd_cleanup coff_object_p (bfd *); extern struct bfd_section *coff_section_from_bfd_index