diff options
author | Alan Modra <amodra@gmail.com> | 2023-06-05 16:25:16 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2023-06-05 16:47:44 +0930 |
commit | fc998e4cb708899b5f75d8d4d2b79ed162437c41 (patch) | |
tree | a0b62f5c851792baca8ef9faa4f2c883306e87dd /bfd | |
parent | 6fc018e9e593a3235dbf7026726ba4665373b741 (diff) | |
download | fsf-binutils-gdb-fc998e4cb708899b5f75d8d4d2b79ed162437c41.zip fsf-binutils-gdb-fc998e4cb708899b5f75d8d4d2b79ed162437c41.tar.gz fsf-binutils-gdb-fc998e4cb708899b5f75d8d4d2b79ed162437c41.tar.bz2 |
bfd_error_on_input messages
bfd_errmsg uses asprintf for bfd_error_on_input, which means we
currently leak memory. Keep a static pointer to the message and free
it in various places to minimise the leaks.
bfd_set_input_error (NULL, bfd_error_no_error) is a way to free up the
last string if that matters.
* bfd.c (input_error_msg): New static var.
(bfd_set_input_error): Free it here..
(bfd_init): ..and here..
(bfd_errmsg): ..and here. Use it for asprintf output.
Diffstat (limited to 'bfd')
-rw-r--r-- | bfd/bfd.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -703,8 +703,9 @@ CODE_FRAGMENT */ static bfd_error_type bfd_error; -static bfd *input_bfd; static bfd_error_type input_error; +static bfd *input_bfd; +static char *input_error_msg; const char *const bfd_errmsgs[] = { @@ -792,6 +793,8 @@ bfd_set_input_error (bfd *input, bfd_error_type error_tag) /* This is an error that occurred during bfd_close when writing an archive, but on one of the input files. */ bfd_error = bfd_error_on_input; + free (input_error_msg); + input_error_msg = NULL; input_bfd = input; input_error = error_tag; if (input_error >= bfd_error_on_input) @@ -818,12 +821,13 @@ bfd_errmsg (bfd_error_type error_tag) #endif if (error_tag == bfd_error_on_input) { - char *buf; const char *msg = bfd_errmsg (input_error); - if (asprintf (&buf, _(bfd_errmsgs [error_tag]), + free (input_error_msg); + input_error_msg = NULL; + if (asprintf (&input_error_msg, _(bfd_errmsgs [error_tag]), bfd_get_filename (input_bfd), msg) != -1) - return buf; + return input_error_msg; /* Ick, what to do on out of memory? */ return msg; @@ -1659,6 +1663,8 @@ bfd_init (void) { bfd_error = bfd_error_no_error; input_bfd = NULL; + free (input_error_msg); + input_error_msg = NULL; input_error = bfd_error_no_error; _bfd_error_program_name = NULL; _bfd_error_internal = error_handler_fprintf; |