aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-04-05 16:44:35 +0930
committerAlan Modra <amodra@gmail.com>2023-04-06 09:51:38 +0930
commit41e6ffcecbcf62ae1f1aee52fad94b4f02b0706f (patch)
tree72b1e7f83784259287b55a54643e36f22fe50802 /binutils/objcopy.c
parentb5bfe9351ba1de20b7ee0fc60a9c0a49b324d872 (diff)
downloadgdb-41e6ffcecbcf62ae1f1aee52fad94b4f02b0706f.zip
gdb-41e6ffcecbcf62ae1f1aee52fad94b4f02b0706f.tar.gz
gdb-41e6ffcecbcf62ae1f1aee52fad94b4f02b0706f.tar.bz2
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.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 957fb85..d4fc644 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -4667,6 +4667,7 @@ write_debugging_info (bfd *obfd, void *dhandle,
flags = SEC_HAS_CONTENTS | SEC_READONLY | SEC_DEBUGGING;
stabsec = bfd_make_section_with_flags (obfd, ".stab", flags);
stabstrsec = bfd_make_section_with_flags (obfd, ".stabstr", flags);
+ ret = true;
if (stabsec == NULL
|| stabstrsec == NULL
|| !bfd_set_section_size (stabsec, symsize)
@@ -4676,18 +4677,17 @@ write_debugging_info (bfd *obfd, void *dhandle,
{
bfd_nonfatal_message (NULL, obfd, NULL,
_("can't create debugging section"));
- free (strings);
- return false;
+ ret = false;
}
/* We can get away with setting the section contents now because
the next thing the caller is going to do is copy over the
real sections. We may someday have to split the contents
setting out of this function. */
- ret = true;
- if (! bfd_set_section_contents (obfd, stabsec, syms, 0, symsize)
- || ! bfd_set_section_contents (obfd, stabstrsec, strings, 0,
- stringsize))
+ if (ret
+ && (!bfd_set_section_contents (obfd, stabsec, syms, 0, symsize)
+ || !bfd_set_section_contents (obfd, stabstrsec, strings, 0,
+ stringsize)))
{
bfd_nonfatal_message (NULL, obfd, NULL,
_("can't set debugging section contents"));