]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
i386 gas: don't leak op_hash or reg_hash memory
authorAlan Modra <amodra@gmail.com>
Thu, 7 Jul 2022 12:36:55 +0000 (22:06 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 9 Jul 2022 12:05:02 +0000 (21:35 +0930)
This tidies memory used by the two x86 gas string hash tables before
exiting.  I'm using a two-pronged approach, firstly the obvious call
to htab_delete plus telling the libiberty/hashtab.c infrastructure to
free tuples generated by str_hash_insert, and secondly putting the x86
core_optab memory on the notes obstack.  It would be possible to free
core_optab memory by using a custom hash table del_f on x86, as I do
for arc, but a later patch will move all the string hash memory to the
notes obstack.

* config/tc-i386.c (md_begin): Use notes_alloc for core_optab.
(386_md_end): New function.
* config/tc-i386.h (386_md_end): Declare.
(md_end): Define.
* hash.h (str_htab_create): Pass free as del_f.

gas/config/tc-i386.c
gas/config/tc-i386.h
gas/hash.h

index 9cd33a91660695cfedad2a027434d44fb515e5b5..d40a71a492ae528aba7d0809638f5e385e4b49db 100644 (file)
@@ -2947,7 +2947,7 @@ md_begin (void)
 
     /* Setup for loop.  */
     optab = i386_optab;
-    core_optab = XNEW (templates);
+    core_optab = notes_alloc (sizeof (*core_optab));
     core_optab->start = optab;
 
     while (1)
@@ -2964,7 +2964,7 @@ md_begin (void)
 
            if (optab->name == NULL)
              break;
-           core_optab = XNEW (templates);
+           core_optab = notes_alloc (sizeof (*core_optab));
            core_optab->start = optab;
          }
       }
@@ -3099,6 +3099,13 @@ i386_print_statistics (FILE *file)
   htab_print_statistics (file, "i386 opcode", op_hash);
   htab_print_statistics (file, "i386 register", reg_hash);
 }
+
+void
+i386_md_end (void)
+{
+  htab_delete (op_hash);
+  htab_delete (reg_hash);
+}
 \f
 #ifdef DEBUG386
 
index 5d6fc7524747905b62eac4f1f9a24159d52a8855..a6e096ee110575885e543de9c41ccecdfb6d0e70 100644 (file)
@@ -216,6 +216,9 @@ extern void i386_cons_align (int);
 void i386_print_statistics (FILE *);
 #define tc_print_statistics i386_print_statistics
 
+void i386_md_end (void);
+#define md_end i386_md_end
+
 extern unsigned int i386_frag_max_var (fragS *);
 #define md_frag_max_var i386_frag_max_var
 
index 21f4a6dc42a471d82549daa61641f10fabe50584..29e882514f449fd3994682f28ba4e9635beaa767 100644 (file)
@@ -99,7 +99,7 @@ static inline htab_t
 str_htab_create (void)
 {
   return htab_create_alloc (16, hash_string_tuple, eq_string_tuple,
-                           NULL, xcalloc, free);
+                           free, xcalloc, free);
 }
 
 #endif /* HASH_H */