libdw/ChangeLog | 10 ++++++++++ libdw/dwarf_begin_elf.c | 13 +++++++++++++ libdw/dwarf_end.c | 4 +++- libdw/libdwP.h | 5 ++++- 4 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 6fb5d8d..c3dbda9 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,5 +1,15 @@ 2012-03-20 Tom Tromey <[email protected]> + * libdwP.h (struct Dwarf) [n_sections]: New field. + [sectiondata]: Change type. + * dwarf_end.c (__libdw_free_zdata): Use n_sections. + (dwarf_end): Free the section data. + * dwarf_begin_elf.c (check_section, valid_p, scngrp_read): Free + the section data. + (dwarf_begin_elf): Allocate the section data. + +2012-03-20 Tom Tromey <[email protected]> + * libdwP.h (IDX_debug_types): Move just before IDX_last. * dwarf_begin_elf.c (dwarf_scnnames): Move .debug_types to the end. diff --git a/libdw/dwarf_begin_elf.c b/libdw/dwarf_begin_elf.c index e62ef07..def8ed6 100644 --- a/libdw/dwarf_begin_elf.c +++ b/libdw/dwarf_begin_elf.c @@ -126,6 +126,7 @@ check_section (Dwarf *result, GElf_Ehdr *ehdr, Elf_Scn *scn, bool inscngrp) invalid. */ __libdw_free_zdata (result); __libdw_seterrno (DWARF_E_INVALID_ELF); + free (result->sectiondata); free (result); return NULL; } @@ -239,6 +240,7 @@ valid_p (Dwarf *result) { __libdw_free_zdata (result); __libdw_seterrno (DWARF_E_NO_DWARF); + free (result->sectiondata); free (result); result = NULL; } @@ -269,6 +271,7 @@ scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, Elf_Scn *scngrp) { /* We cannot read the section content. Fail! */ __libdw_free_zdata (result); + free (result->sectiondata); free (result); return NULL; } @@ -286,6 +289,7 @@ scngrp_read (Dwarf *result, Elf *elf, GElf_Ehdr *ehdr, Elf_Scn *scngrp) never happen. */ __libdw_free_zdata (result); __libdw_seterrno (DWARF_E_INVALID_ELF); + free (result->sectiondata); free (result); return NULL; } @@ -351,6 +355,15 @@ dwarf_begin_elf (elf, cmd, scngrp) result->mem_tail->remaining = result->mem_tail->size; result->mem_tail->prev = NULL; + result->n_sections = IDX_last; + result->sectiondata = calloc (result->n_sections, sizeof (Dwarf_Section)); + if (unlikely (result->sectiondata == NULL)) + { + free (result); + __libdw_seterrno (DWARF_E_NOMEM); + return NULL; + } + if (cmd == DWARF_C_READ || cmd == DWARF_C_RDWR) { /* If the caller provides a section group we get the DWARF diff --git a/libdw/dwarf_end.c b/libdw/dwarf_end.c index 2636c69..a2ee8d6 100644 --- a/libdw/dwarf_end.c +++ b/libdw/dwarf_end.c @@ -85,7 +85,7 @@ __libdw_free_zdata (Dwarf *dwarf) { size_t i; - for (i = 0; i < IDX_last; ++i) + for (i = 0; i < dwarf->n_sections; ++i) { if (dwarf->sectiondata[i].gzipped) free (dwarf->sectiondata[i].data); @@ -125,6 +125,8 @@ dwarf_end (dwarf) __libdw_free_zdata (dwarf); + free (dwarf->sectiondata); + /* Free the ELF descriptor if necessary. */ if (dwarf->free_elf) elf_end (dwarf->elf); diff --git a/libdw/libdwP.h b/libdw/libdwP.h index b24ac0b..fee0bac 100644 --- a/libdw/libdwP.h +++ b/libdw/libdwP.h @@ -161,8 +161,11 @@ struct Dwarf /* The underlying ELF file. */ Elf *elf; + /* The number of sections in SECTIONDATA. */ + size_t n_sections; + /* The section data. */ - struct Dwarf_Section sectiondata[IDX_last]; + struct Dwarf_Section *sectiondata; /* True if the file has a byte order different from the host. */ bool other_byte_order; -- 1.7.7.6 _______________________________________________ elfutils-devel mailing list [email protected] https://fedorahosted.org/mailman/listinfo/elfutils-devel
