aboutsummaryrefslogtreecommitdiff
path: root/binutils/rddbg.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-03-31 13:36:16 +1030
committerAlan Modra <amodra@gmail.com>2023-04-03 07:29:35 +0930
commita6336913332303c45608d77b731bee5c3a3095e0 (patch)
tree242a75f53aeb5eafb0122f70107574ad3c178929 /binutils/rddbg.c
parent31991eaaeee55fbf077e5c7ed1bc5deece050933 (diff)
downloadgdb-a6336913332303c45608d77b731bee5c3a3095e0.zip
gdb-a6336913332303c45608d77b731bee5c3a3095e0.tar.gz
gdb-a6336913332303c45608d77b731bee5c3a3095e0.tar.bz2
rddbg.c stabs FIXMEs
This should sort out some very old FIXMEs in code handling stabs debug info. Necessary if we are to fuss over freeing up memory before objdump and objcopy exit. It is of course better from a user viewpoint to *not* free memory, which takes some time, and leave that to process exit. The only reason to do so is that having many memory leaks in binutils/ code tends to hide leaks in bfd/ or opcodes/, which we should care about. * budbg.h (parse_stab): Update prototype. * debug.h (debug_start_source): Update prototype. * debug.c (debug_start_source): Add name_used. Set if stashed. * rddbg.c (read_symbol_stabs_debugging_info): Always malloc stab string passed to parse_stab. Free stab string when unreferenced. (read_section_stabs_debugging_info): Likewise, and strings section contents. * stabs.c (parse_stab): Add string_used param. Set if string stashed. Pass to debug_start_source. Realloc file_types array rather that using malloc. Clarify comment about debug_make_indirect_type.
Diffstat (limited to 'binutils/rddbg.c')
-rw-r--r--binutils/rddbg.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/binutils/rddbg.c b/binutils/rddbg.c
index 15081c3..fb59f52 100644
--- a/binutils/rddbg.c
+++ b/binutils/rddbg.c
@@ -194,6 +194,7 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
{
size_t len;
char *f, *s;
+ bool f_used;
if (stroff + strx >= strsize)
{
@@ -238,10 +239,13 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
free (f);
f = s;
}
+ if (!f)
+ f = xstrdup (s);
save_stab (type, desc, value, s);
- if (! parse_stab (dhandle, shandle, type, desc, value, s))
+ if (! parse_stab (dhandle, shandle, type, desc, value,
+ f, &f_used))
{
stab_context ();
free_saved_stabs ();
@@ -252,18 +256,14 @@ read_section_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
return false;
}
- /* Don't free f, since I think the stabs code
- expects strings to hang around. This should be
- straightened out. FIXME. */
+ if (!f_used)
+ free (f);
}
}
free_saved_stabs ();
free (stabs);
-
- /* Don't free strings, since I think the stabs code expects
- the strings to hang around. This should be straightened
- out. FIXME. */
+ free (strings);
}
}
@@ -297,6 +297,7 @@ read_symbol_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
{
const char *s;
char *f;
+ bool f_used;
if (shandle == NULL)
{
@@ -327,20 +328,22 @@ read_symbol_stabs_debugging_info (bfd *abfd, asymbol **syms, long symcount,
f = n;
s = n;
}
+ if (!f)
+ f = xstrdup (s);
save_stab (i.stab_type, i.stab_desc, i.value, s);
if (! parse_stab (dhandle, shandle, i.stab_type, i.stab_desc,
- i.value, s))
+ i.value, f, &f_used))
{
stab_context ();
+ free (f);
free_saved_stabs ();
return false;
}
- /* Don't free f, since I think the stabs code expects
- strings to hang around. This should be straightened out.
- FIXME. */
+ if (!f_used)
+ free (f);
}
}