From: Alan Modra Date: Wed, 1 Jan 2025 12:19:48 +0000 (+1030) Subject: gas reloc_list memory leaks X-Git-Tag: binutils-2_44~295 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d4faef1077bdd21d3515eb0355bd406652758b3a;p=thirdparty%2Fbinutils-gdb.git gas reloc_list memory leaks 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. --- diff --git a/gas/config/tc-wasm32.c b/gas/config/tc-wasm32.c index e7db729c5f3..88a20805891 100644 --- a/gas/config/tc-wasm32.c +++ b/gas/config/tc-wasm32.c @@ -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; diff --git a/gas/read.c b/gas/read.c index 94e12549d4f..5be2686822d 100644 --- a/gas/read.c +++ b/gas/read.c @@ -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; diff --git a/gas/write.c b/gas/write.c index d96d8c20dbd..c52a16947e5 100644 --- a/gas/write.c +++ b/gas/write.c @@ -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 ();