diff options
author | Alan Modra <amodra@gmail.com> | 2023-01-27 10:31:56 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-01-27 15:38:52 +1030 |
commit | c026360c7578b4599c289987981d9c9c80481e40 (patch) | |
tree | 695998bd2116183a34814b02cd44d44316f6674b /gas/config/tc-iq2000.c | |
parent | 48afe8b710712bf131fadbfa3278e512a7034483 (diff) | |
download | gdb-c026360c7578b4599c289987981d9c9c80481e40.zip gdb-c026360c7578b4599c289987981d9c9c80481e40.tar.gz gdb-c026360c7578b4599c289987981d9c9c80481e40.tar.bz2 |
gas macro memory leaks
This tidies memory allocated for entries in macro_hash. Freeing the
macro name requires a little restructuring of the define_macro
interface due to the name being used in the error message, and exposed
the fact that the name and other fields were not initialised by the
iq2000 backend.
There is also a fix for
.macro .macro
.endm
.macro .macro
.endm
which prior to this patch reported
mac.s:1: Warning: attempt to redefine pseudo-op `.macro' ignored
mac.s:3: Error: Macro `.macro' was already defined
rather than reporting the attempt to redefine twice.
* macro.c (macro_del_f): New function.
(macro_init): Use it when creating macro_hash.
(free_macro): Free macro name too.
(define_macro): Return the macro_entry, remove idx, file, line and
namep params. Call as_where. Report errors here. Delete macro
from macro_hash on attempt to redefined pseudo-op.
(delete_macro): Don't call free_macro.
* macro.h (define_macro): Update prototype.
* read.c (s_macro): Adjust to suit.
* config/tc-iq2000.c (iq2000_add_macro): Init all fields of
macro_entry.
Diffstat (limited to 'gas/config/tc-iq2000.c')
-rw-r--r-- | gas/config/tc-iq2000.c | 16 |
1 files changed, 5 insertions, 11 deletions
diff --git a/gas/config/tc-iq2000.c b/gas/config/tc-iq2000.c index f5d7c90..4e16972 100644 --- a/gas/config/tc-iq2000.c +++ b/gas/config/tc-iq2000.c @@ -229,15 +229,14 @@ iq2000_add_macro (const char * name, const char ** arguments) { macro_entry *macro; - sb macro_name; - const char *namestr; macro = XNEW (macro_entry); + macro->name = xstrdup (name); sb_new (& macro->sub); - sb_new (& macro_name); - macro->formal_count = 0; macro->formals = 0; + macro->formal_hash = str_htab_create (); + macro->file = as_where (¯o->line); sb_add_string (& macro->sub, semantics); @@ -245,9 +244,6 @@ iq2000_add_macro (const char * name, { formal_entry ** p = ¯o->formals; - macro->formal_count = 0; - macro->formal_hash = str_htab_create (); - while (*arguments != NULL) { formal_entry *formal; @@ -261,7 +257,7 @@ iq2000_add_macro (const char * name, /* chlm: Added the following to allow defaulted args. */ if (strchr (*arguments,'=')) { - char * tt_args = strdup (*arguments); + char * tt_args = xstrdup (*arguments); char * tt_dflt = strchr (tt_args,'='); *tt_dflt = 0; @@ -283,9 +279,7 @@ iq2000_add_macro (const char * name, } } - sb_add_string (¯o_name, name); - namestr = sb_terminate (¯o_name); - str_hash_insert (macro_hash, namestr, macro, 1); + str_hash_insert (macro_hash, macro->name, macro, 1); macro_defined = 1; } |