objcopy write_debugging_info memory leaks
authorAlan Modra <amodra@gmail.com>
Wed, 5 Apr 2023 07:14:35 +0000 (16:44 +0930)
committerAlan Modra <amodra@gmail.com>
Thu, 6 Apr 2023 00:21:38 +0000 (09:51 +0930)
commit41e6ffcecbcf62ae1f1aee52fad94b4f02b0706f
tree72b1e7f83784259287b55a54643e36f22fe50802
parentb5bfe9351ba1de20b7ee0fc60a9c0a49b324d872
objcopy write_debugging_info memory leaks

The old stabs code didn't bother too much about freeing memory.
This patch corrects that and avoids some dubious copying of strings.

* objcopy.c (write_debugging_info): Free both strings and
syms on failure to create sections.
* wrstabs.c: Delete unnecessary forward declarations and casts
throughout file.
(stab_write_symbol_and_free): New function.  Use it
throughout, simplifying return paths.
(stab_push_string): Don't strdup string.  Use it thoughout
for malloced strings.
(stab_push_string_dup): New function.  Use it throughout for
strings in auto buffers.
(write_stabs_in_sections_debugging_info): Free malloced memory.
(stab_enum_type): Increase buffer sizing for worst case.
(stab_range_type, stab_array_type): Reduce buffer size.
(stab_set_type): Likewise.
(stab_method_type): Free args on error return.  Correct
buffer size.
(stab_struct_field): Fix memory leaks.
(stab_class_static_member, stab_class_baseclass): Likewise.
(stab_start_class_type): Likewise.  Correct buffer size.
(stab_class_start_method): Correct buffer size.
(stab_class_method_var): Free memory on error return.
(stab_start_function): Fix "rettype" memory leak.
binutils/objcopy.c
binutils/wrstabs.c