From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 336DC3858031; Wed, 14 Jun 2023 04:57:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 336DC3858031 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] Re: bfd/elf.c strtab memory leak X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 3bedac2939328dc74e9bfa36a26201ec0d9e0b61 X-Git-Newrev: 48375c36dc59e3c0e6b9bf38f17f4692bddb578f Message-Id: <20230614045750.336DC3858031@sourceware.org> Date: Wed, 14 Jun 2023 04:57:50 +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: Wed, 14 Jun 2023 04:57:50 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D48375c36dc59= e3c0e6b9bf38f17f4692bddb578f commit 48375c36dc59e3c0e6b9bf38f17f4692bddb578f Author: Alan Modra Date: Wed Jun 14 13:46:56 2023 +0930 Re: bfd/elf.c strtab memory leak =20 There are other places that leak the strtab. =20 * elf.c (_bfd_elf_compute_section_file_positions): Free strtab on error paths. Diff: --- bfd/elf.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bfd/elf.c b/bfd/elf.c index c4e2f89a16e..8f6d7d1adba 100644 --- a/bfd/elf.c +++ b/bfd/elf.c @@ -4254,11 +4254,7 @@ _bfd_elf_compute_section_file_positions (bfd *abfd, { bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed); if (failed) - { - if (need_symtab) - _bfd_elf_strtab_free (strtab); - return false; - } + goto err_free_strtab; } =20 shstrtab_hdr =3D &elf_tdata (abfd)->shstrtab_hdr; @@ -4274,9 +4270,9 @@ _bfd_elf_compute_section_file_positions (bfd *abfd, shstrtab_hdr->sh_addralign =3D 1; =20 if (!assign_file_positions_except_relocs (abfd, link_info)) - return false; + goto err_free_strtab; =20 - if (need_symtab) + if (strtab !=3D NULL) { file_ptr off; Elf_Internal_Shdr *hdr; @@ -4303,13 +4299,17 @@ _bfd_elf_compute_section_file_positions (bfd *abfd, out. */ if (bfd_seek (abfd, hdr->sh_offset, SEEK_SET) !=3D 0 || ! _bfd_elf_strtab_emit (abfd, strtab)) - return false; + goto err_free_strtab; _bfd_elf_strtab_free (strtab); } =20 abfd->output_has_begun =3D true; - return true; + + err_free_strtab: + if (strtab !=3D NULL) + _bfd_elf_strtab_free (strtab); + return false; } =20 /* Retrieve .eh_frame_hdr. Prior to size_dynamic_sections the