*dwarf2.c: Revert previous patch.  All of the allocate memory is
        on an obstack which will be freed at some other time.
This commit is contained in:
Nick Clifton 2008-02-22 15:27:38 +00:00
parent 5ad3420347
commit 34b5e0b205
2 changed files with 21 additions and 82 deletions

View File

@ -1,3 +1,9 @@
2008-02-22 Nick Clifton <nickc@redhat.com>
PR 868
*dwarf2.c: Revert previous patch. All of the allocate memory is
on an obstack which will be freed at some other time.
2008-02-20 Nick Clifton <nickc@redhat.com> 2008-02-20 Nick Clifton <nickc@redhat.com>
PR 868 PR 868

View File

@ -656,16 +656,10 @@ read_abbrevs (bfd *abfd, bfd_uint64_t offset, struct dwarf2_debug *stash)
while (abbrev) while (abbrev)
{ {
struct abbrev_info * a = abbrev; free (abbrev->attrs);
abbrev = abbrev->next;
abbrev = a->next;
if (a->attrs)
free (abbrev->attrs);
free (a);
} }
} }
free (abbrevs);
return NULL; return NULL;
} }
cur_abbrev->attrs = tmp; cur_abbrev->attrs = tmp;
@ -1129,11 +1123,9 @@ arange_add (bfd *abfd, struct arange *first_arange, bfd_vma low_pc, bfd_vma high
first_arange->next = arange; first_arange->next = arange;
} }
/* Decode the line number information for UNIT. /* Decode the line number information for UNIT. */
Note: this function allocates memory. It is the caller's
responsibility to free it. */
static struct line_info_table * static struct line_info_table*
decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash) decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
{ {
bfd *abfd = unit->abfd; bfd *abfd = unit->abfd;
@ -1255,7 +1247,6 @@ decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
if (tmp == NULL) if (tmp == NULL)
{ {
free (table->dirs); free (table->dirs);
free (table);
return NULL; return NULL;
} }
table->dirs = tmp; table->dirs = tmp;
@ -1283,7 +1274,6 @@ decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
{ {
free (table->files); free (table->files);
free (table->dirs); free (table->dirs);
free (table);
return NULL; return NULL;
} }
table->files = tmp; table->files = tmp;
@ -1380,7 +1370,6 @@ decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
{ {
free (table->files); free (table->files);
free (table->dirs); free (table->dirs);
free (table);
free (filename); free (filename);
return NULL; return NULL;
} }
@ -1404,7 +1393,6 @@ decode_line_info (struct comp_unit *unit, struct dwarf2_debug *stash)
free (filename); free (filename);
free (table->files); free (table->files);
free (table->dirs); free (table->dirs);
free (table);
return NULL; return NULL;
} }
break; break;
@ -1826,10 +1814,7 @@ read_rangelist (struct comp_unit *unit, struct arange *arange, bfd_uint64_t offs
/* DWARF2 Compilation unit functions. */ /* DWARF2 Compilation unit functions. */
/* Scan over each die in a comp. unit looking for functions to add /* Scan over each die in a comp. unit looking for functions to add
to the function table and variables to the variable table. to the function table and variables to the variable table. */
Returns TRUE upon success, FALSE otherwise. Allocates memory
blocks to the unit->function_table and unit->variable_table fields.
It is the caller's responsibility to free this memory. */
static bfd_boolean static bfd_boolean
scan_unit_for_symbols (struct comp_unit *unit) scan_unit_for_symbols (struct comp_unit *unit)
@ -1846,7 +1831,7 @@ scan_unit_for_symbols (struct comp_unit *unit)
nested_funcs = bfd_malloc (nested_funcs_size * sizeof (struct funcinfo *)); nested_funcs = bfd_malloc (nested_funcs_size * sizeof (struct funcinfo *));
if (nested_funcs == NULL) if (nested_funcs == NULL)
return FALSE; return FALSE;
nested_funcs[nesting_level] = NULL; nested_funcs[nesting_level] = 0;
while (nesting_level) while (nesting_level)
{ {
@ -1883,7 +1868,6 @@ scan_unit_for_symbols (struct comp_unit *unit)
|| abbrev->tag == DW_TAG_inlined_subroutine) || abbrev->tag == DW_TAG_inlined_subroutine)
{ {
bfd_size_type amt = sizeof (struct funcinfo); bfd_size_type amt = sizeof (struct funcinfo);
func = bfd_zalloc (abfd, amt); func = bfd_zalloc (abfd, amt);
func->tag = abbrev->tag; func->tag = abbrev->tag;
func->prev_func = unit->function_table; func->prev_func = unit->function_table;
@ -1905,7 +1889,6 @@ scan_unit_for_symbols (struct comp_unit *unit)
if (abbrev->tag == DW_TAG_variable) if (abbrev->tag == DW_TAG_variable)
{ {
bfd_size_type amt = sizeof (struct varinfo); bfd_size_type amt = sizeof (struct varinfo);
var = bfd_zalloc (abfd, amt); var = bfd_zalloc (abfd, amt);
var->tag = abbrev->tag; var->tag = abbrev->tag;
var->stack = 1; var->stack = 1;
@ -3218,75 +3201,25 @@ _bfd_dwarf2_cleanup_debug_info (bfd *abfd)
for (each = stash->all_comp_units; each; each = each->next_unit) for (each = stash->all_comp_units; each; each = each->next_unit)
{ {
struct funcinfo * function_table = each->function_table; struct abbrev_info **abbrevs = each->abbrevs;
struct varinfo * variable_table = each->variable_table; size_t i;
if (each->abbrevs != NULL) for (i = 0; i < ABBREV_HASH_SIZE; i++)
{ {
size_t i; struct abbrev_info *abbrev = abbrevs[i];
for (i = 0; i < ABBREV_HASH_SIZE; i++) while (abbrev)
{ {
struct abbrev_info *abbrev = each->abbrevs[i]; free (abbrev->attrs);
abbrev = abbrev->next;
while (abbrev)
{
struct abbrev_info * a = abbrev;
abbrev = a->next;
if (a->attrs)
free (a->attrs);
free (a);
}
} }
free (each->abbrevs);
each->abbrevs = NULL;
} }
if (each->line_table) if (each->line_table)
{ {
/* FIXME: We should free the line_info structures as well. */ free (each->line_table->dirs);
if (each->line_table->dirs) free (each->line_table->files);
free (each->line_table->dirs);
if (each->line_table->files)
free (each->line_table->files);
free (each->line_table);
each->line_table = NULL;
} }
while (function_table)
{
struct funcinfo * f = function_table;
function_table = f->prev_func;
if (f->file)
free (f->file);
if (f->caller_file)
free (f->caller_file);
free (f);
}
each->function_table = NULL;
while (variable_table)
{
struct varinfo * v = variable_table;
variable_table = variable_table->prev_var;
if (v->file)
free (v->file);
free (v);
}
each->variable_table = NULL;
} }
free (stash->dwarf_abbrev_buffer); free (stash->dwarf_abbrev_buffer);