From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 2BDFC3858D1E; Wed, 21 Jun 2023 06:20:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2BDFC3858D1E 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] elf32_arm_get_synthetic_symtab memory leak X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 9a925d0dad55a3cd4e493642b81c668d2ab09d1d X-Git-Newrev: 08edd976116312550831cdfd3b5a4b069bdcca80 Message-Id: <20230621062001.2BDFC3858D1E@sourceware.org> Date: Wed, 21 Jun 2023 06:20:01 +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, 21 Jun 2023 06:20:01 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D08edd9761163= 12550831cdfd3b5a4b069bdcca80 commit 08edd976116312550831cdfd3b5a4b069bdcca80 Author: Alan Modra Date: Wed Jun 21 14:33:59 2023 +0930 elf32_arm_get_synthetic_symtab memory leak =20 ARM get_synthetic_symtab reads .plt and caches that data. Caching the data doesn't make a lot of sense since get_synthetic_symtab is only called once per bfd, and the memory might be put to better use. It also leaks on closing the bfd. =20 * elf32-arm.c (elf32_arm_get_synthetic_symtab): Don't cache plt contents. Free plt data before returning. Diff: --- bfd/elf32-arm.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 2afe67abdf1..3b7cee3de1c 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -20073,15 +20073,9 @@ elf32_arm_get_synthetic_symtab (bfd *abfd, if (!elf32_arm_size_info.slurp_reloc_table (abfd, relplt, dynsyms, true)) return -1; =20 - data =3D plt->contents; - if (data =3D=3D NULL) - { - if (!bfd_get_full_section_contents (abfd, plt, &data) - || data =3D=3D NULL) - return -1; - plt->contents =3D data; - plt->flags |=3D SEC_IN_MEMORY; - } + data =3D NULL; + if (!bfd_get_full_section_contents (abfd, plt, &data)) + return -1; =20 count =3D NUM_SHDR_ENTRIES (hdr); size =3D count * sizeof (asymbol); @@ -20093,13 +20087,13 @@ elf32_arm_get_synthetic_symtab (bfd *abfd, size +=3D sizeof ("+0x") - 1 + 8; } =20 - s =3D *ret =3D (asymbol *) bfd_malloc (size); - if (s =3D=3D NULL) - return -1; - offset =3D elf32_arm_plt0_size (abfd, data); - if (offset =3D=3D (bfd_vma) -1) - return -1; + if (offset =3D=3D (bfd_vma) -1 + || (s =3D *ret =3D (asymbol *) bfd_malloc (size)) =3D=3D NULL) + { + free (data); + return -1; + } =20 names =3D (char *) (s + count); p =3D relplt->relocation; @@ -20144,6 +20138,7 @@ elf32_arm_get_synthetic_symtab (bfd *abfd, offset +=3D plt_size; } =20 + free (data); return n; }