From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: arc gas: don't leak arc_opcode_hash memory
Date: Sat, 9 Jul 2022 22:02:49 +0930 [thread overview]
Message-ID: <Ysl1cbg35NvPC02C@squeak.grove.modra.org> (raw)
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.
* 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 --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++;
}
+static void
+arc_opcode_free (void *elt)
+{
+ string_tuple_t *tuple = (string_tuple_t *) elt;
+ struct arc_opcode_hash_entry *entry = (void *) tuple->value;
+ free (entry->opcode);
+ free (entry);
+ free (tuple);
+}
/* 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);
/* Set up a hash table for the instructions. */
- arc_opcode_hash = str_htab_create ();
+ arc_opcode_hash = htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
+ arc_opcode_free, xcalloc, free);
/* Initialize the hash table with the insns. */
do
@@ -2710,6 +2720,15 @@ md_begin (void)
declare_addrtype ("cxd", ARC_NPS400_ADDRTYPE_CXD);
}
+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. */
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;
};
+extern void arc_md_end (void);
+#define md_end arc_md_end
+
#endif
--
Alan Modra
Australia Development Lab, IBM
reply other threads:[~2022-07-09 12:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Ysl1cbg35NvPC02C@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).