From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1062) id 2D1EF385BAC9; Sat, 9 Jul 2022 12:36:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2D1EF385BAC9 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] arc gas: don't leak arc_opcode_hash memory X-Act-Checkin: binutils-gdb X-Git-Author: Alan Modra X-Git-Refname: refs/heads/master X-Git-Oldrev: 654d6f31a644d1381c76d3d70ce3ca9f45a08597 X-Git-Newrev: a51628a9d49bf7abb89b71032aa38d7f596be674 Message-Id: <20220709123626.2D1EF385BAC9@sourceware.org> Date: Sat, 9 Jul 2022 12:36:26 +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: Sat, 09 Jul 2022 12:36:26 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Da51628a9d49b= f7abb89b71032aa38d7f596be674 commit a51628a9d49bf7abb89b71032aa38d7f596be674 Author: Alan Modra Date: Thu Jul 7 22:09:28 2022 +0930 arc gas: don't leak arc_opcode_hash memory =20 The arc opcode hash table has entries that have a realloc'd field. This doesn't lend itself to obstack allocation, so freeing must be done with a purpose built hashtab del_f. =20 * config/tc-arc.c (arc_opcode_free): New function. (md_begin): Pass the above as del_f to htab_create_alloc. (arc_md_end): New function. * config/tc-arc.h (arc_md_end): Declare. (md_end): Define. Diff: --- gas/config/tc-arc.c | 21 ++++++++++++++++++++- gas/config/tc-arc.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gas/config/tc-arc.c b/gas/config/tc-arc.c index 6c5b1d68078..fd648b742b4 100644 --- a/gas/config/tc-arc.c +++ b/gas/config/tc-arc.c @@ -774,6 +774,15 @@ arc_insert_opcode (const struct arc_opcode *opcode) entry->count++; } =20 +static void +arc_opcode_free (void *elt) +{ + string_tuple_t *tuple =3D (string_tuple_t *) elt; + struct arc_opcode_hash_entry *entry =3D (void *) tuple->value; + free (entry->opcode); + free (entry); + free (tuple); +} =20 /* Like md_number_to_chars but for middle-endian values. The 4-byte limm value, is encoded as 'middle-endian' for a little-endian target. This @@ -2605,7 +2614,8 @@ md_begin (void) bfd_set_private_flags (stdoutput, selected_cpu.eflags); =20 /* Set up a hash table for the instructions. */ - arc_opcode_hash =3D str_htab_create (); + arc_opcode_hash =3D htab_create_alloc (16, hash_string_tuple, eq_string_= tuple, + arc_opcode_free, xcalloc, free); =20 /* Initialize the hash table with the insns. */ do @@ -2710,6 +2720,15 @@ md_begin (void) declare_addrtype ("cxd", ARC_NPS400_ADDRTYPE_CXD); } =20 +void +arc_md_end (void) +{ + htab_delete (arc_opcode_hash); + htab_delete (arc_reg_hash); + htab_delete (arc_aux_hash); + htab_delete (arc_addrtype_hash); +} + /* Write a value out to the object file, using the appropriate endianness. */ =20 diff --git a/gas/config/tc-arc.h b/gas/config/tc-arc.h index 29b4582ae22..d7b989e7f19 100644 --- a/gas/config/tc-arc.h +++ b/gas/config/tc-arc.h @@ -268,4 +268,7 @@ struct arc_relax_type int nflg; }; =20 +extern void arc_md_end (void); +#define md_end arc_md_end + #endif