/* This function is used to recursively free the chunks still allocated, and forward chained through the aa_next pointer. */ static void _dwarf_recursive_free(Dwarf_Alloc_Area alloc_area) { if (alloc_area->aa_next != NULL) { _dwarf_recursive_free(alloc_area->aa_next); } alloc_area->aa_next = 0; alloc_area->aa_prev = 0; free(alloc_area); }
/* Used to free all space allocated for this Dwarf_Debug. The caller should assume that the Dwarf_Debug pointer itself is no longer valid upon return from this function. In case of difficulty, this function simply returns quietly. */ int _dwarf_free_all_of_one_debug(Dwarf_Debug dbg) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Shalf i; if (dbg == NULL) return (DW_DLV_ERROR); #ifdef DWARF_SIMPLE_MALLOC if(dbg->de_simple_malloc_base) { struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base; while( smp) { int i; struct simple_malloc_record_s *prev_smp = 0; for(i = 0; i < smp->sr_used; ++i) { struct simple_malloc_entry_s *cur; cur = &smp->sr_entry[i]; if(cur->se_addr != 0) { free(cur->se_addr); cur->se_addr = 0; } } prev_smp = smp; smp = smp->sr_next; free(prev_smp); } dbg->de_simple_malloc_base = 0; dbg->de_simple_malloc_current = 0; } #else for (i = 1; i < ALLOC_AREA_REAL_TABLE_MAX; i++) { int indx = i; alloc_hdr = &dbg->de_alloc_hdr[indx]; if (alloc_hdr->ah_alloc_area_head != NULL) { _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head); } } #endif memset(dbg,0, sizeof(*dbg)); /* prevent accidental use later */ free(dbg); return (DW_DLV_OK); }
/* Used to free all space allocated for this Dwarf_Debug. The caller should assume that the Dwarf_Debug pointer itself is no longer valid upon return from this function. In case of difficulty, this function simply returns quietly. */ int _dwarf_free_all_of_one_debug ( Dwarf_Debug dbg ) { Dwarf_Alloc_Hdr alloc_hdr; Dwarf_Shalf i; if (dbg == NULL) return(DW_DLV_ERROR); for (i = 1; i < ALLOC_AREA_REAL_TABLE_MAX; i++) { int indx = i; alloc_hdr = &dbg->de_alloc_hdr[indx]; if (alloc_hdr->ah_alloc_area_head != NULL) { _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head); } } memset(dbg, 0, sizeof(*dbg)); /* prevent accidental use later */ free(dbg); return(DW_DLV_OK); }
/* Used to free all space allocated for this Dwarf_Debug. The caller should assume that the Dwarf_Debug pointer itself is no longer valid upon return from this function. In case of difficulty, this function simply returns quietly. */ int _dwarf_free_all_of_one_debug(Dwarf_Debug dbg) { Dwarf_Alloc_Hdr alloc_hdr = 0; Dwarf_Shalf i = 0; if (dbg == NULL) { return (DW_DLV_ERROR); } /* To do complete validation that we have no surprising missing or erroneous deallocs it is advisable to do the dwarf_deallocs here that are not things the user can otherwise request. Housecleaning. */ freecontextlist(dbg,&dbg->de_info_reading); freecontextlist(dbg,&dbg->de_types_reading); /* Housecleaning done. Now really free all the space. */ #ifdef DWARF_SIMPLE_MALLOC if (dbg->de_simple_malloc_base) { struct simple_malloc_record_s *smp = dbg->de_simple_malloc_base; while (smp) { int i; struct simple_malloc_record_s *prev_smp = 0; for (i = 0; i < smp->sr_used; ++i) { struct simple_malloc_entry_s *cur; cur = &smp->sr_entry[i]; if (cur->se_addr != 0) { free(cur->se_addr); cur->se_addr = 0; } } prev_smp = smp; smp = smp->sr_next; free(prev_smp); } dbg->de_simple_malloc_base = 0; } #else for (i = 1; i < ALLOC_AREA_REAL_TABLE_MAX; i++) { int indx = i; alloc_hdr = &dbg->de_alloc_hdr[indx]; if (alloc_hdr->ah_alloc_area_head != NULL) { _dwarf_recursive_free(alloc_hdr->ah_alloc_area_head); } } #endif rela_free(&dbg->de_debug_info); rela_free(&dbg->de_debug_types); rela_free(&dbg->de_debug_abbrev); rela_free(&dbg->de_debug_line); rela_free(&dbg->de_debug_loc); rela_free(&dbg->de_debug_aranges); rela_free(&dbg->de_debug_macinfo); rela_free(&dbg->de_debug_pubnames); rela_free(&dbg->de_debug_str); rela_free(&dbg->de_debug_frame); rela_free(&dbg->de_debug_frame_eh_gnu); rela_free(&dbg->de_debug_pubtypes); rela_free(&dbg->de_debug_funcnames); rela_free(&dbg->de_debug_typenames); rela_free(&dbg->de_debug_varnames); rela_free(&dbg->de_debug_weaknames); rela_free(&dbg->de_debug_ranges); dwarf_harmless_cleanout(&dbg->de_harmless_errors); memset(dbg, 0, sizeof(*dbg)); /* Prevent accidental use later. */ free(dbg); return (DW_DLV_OK); }