]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gas reloc_list memory leaks
authorAlan Modra <amodra@gmail.com>
Wed, 1 Jan 2025 12:19:48 +0000 (22:49 +1030)
committerAlan Modra <amodra@gmail.com>
Wed, 1 Jan 2025 12:19:48 +0000 (22:49 +1030)
Put these on the notes obstack too.

* config/tc-wasm32.c (wasm32_leb128): Use notes_alloc for
reloc_list vars.
* read.c (s_reloc): Likewise.
* write.c (create_note_reloc): Likewise.
(write_object_file): Reset reloc_list after write_relocs.

gas/config/tc-wasm32.c
gas/read.c
gas/write.c

index e7db729c5f36206fe48247abdf47b6447e7d15d0..88a20805891d10e0bdd1d34fac0b3df6c66e3887 100644 (file)
@@ -368,7 +368,7 @@ wasm32_leb128 (char **line, int bits, int sign)
       return str != str0;
     }
 
-  reloc = XNEW (struct reloc_list);
+  reloc = notes_alloc (sizeof (*reloc));
   reloc->u.a.offset_sym = expr_build_dot ();
   if (ex.X_op == O_symbol)
     {
@@ -411,7 +411,7 @@ wasm32_leb128 (char **line, int bits, int sign)
 
          signature = strndup (input_line_pointer + 1, siglength);
 
-         reloc2 = XNEW (struct reloc_list);
+         reloc2 = notes_alloc (sizeof (*reloc2));
          reloc2->u.a.offset_sym = expr_build_dot ();
          reloc2->u.a.sym = symbol_find_or_make (signature);
          reloc2->u.a.addend = 0;
index 94e12549d4ff73d5cea3900b1910ab69401275bc..5be2686822d6f1556d0ff8dd9b9a4a782d071357 100644 (file)
@@ -4354,7 +4354,7 @@ s_reloc (int ignore ATTRIBUTE_UNUSED)
     { "64", BFD_RELOC_64 }
   };
 
-  reloc = XNEW (struct reloc_list);
+  reloc = notes_alloc (sizeof (*reloc));
 
   if (flag_mri)
     stop = mri_comment_field (&stopc);
@@ -4433,7 +4433,6 @@ s_reloc (int ignore ATTRIBUTE_UNUSED)
       as_bad (_("bad reloc expression"));
     err_out:
       ignore_rest_of_line ();
-      free (reloc);
       if (flag_mri)
        mri_comment_end (stop, stopc);
       return;
index d96d8c20dbd232bd19c56caa9159d57641483d09..c52a16947e51b8792050bae5d1cbc1b24c6063f6 100644 (file)
@@ -1975,7 +1975,7 @@ create_note_reloc (segT           sec,
 {
   struct reloc_list * reloc;
 
-  reloc = XNEW (struct reloc_list);
+  reloc = notes_alloc (sizeof (*reloc));
 
   /* We create a .b type reloc as resolve_reloc_expr_symbols() has already been called.  */
   reloc->u.b.sec           = sec;
@@ -2535,6 +2535,7 @@ write_object_file (void)
 #endif
 
   bfd_map_over_sections (stdoutput, write_relocs, (char *) 0);
+  reloc_list = NULL;
 
 #ifdef tc_frob_file_after_relocs
   tc_frob_file_after_relocs ();