Path: blob/main/contrib/elftoolchain/libdwarf/dwarf_dealloc.c
39536 views
/*-1* Copyright (c) 2007 John Birrell ([email protected])2* All rights reserved.3*4* Redistribution and use in source and binary forms, with or without5* modification, are permitted provided that the following conditions6* are met:7* 1. Redistributions of source code must retain the above copyright8* notice, this list of conditions and the following disclaimer.9* 2. Redistributions in binary form must reproduce the above copyright10* notice, this list of conditions and the following disclaimer in the11* documentation and/or other materials provided with the distribution.12*13* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND14* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE15* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE16* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE17* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL18* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS19* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)20* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT21* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY22* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF23* SUCH DAMAGE.24*/2526#include "_libdwarf.h"2728ELFTC_VCSID("$Id: dwarf_dealloc.c 2073 2011-10-27 03:30:47Z jkoshy $");2930void31dwarf_dealloc(Dwarf_Debug dbg, Dwarf_Ptr p, Dwarf_Unsigned alloc_type)32{33Dwarf_Abbrev ab;34Dwarf_AttrDef ad, tad;35Dwarf_Attribute at, tat;36Dwarf_Die die;3738/*39* This libdwarf implementation does not use the SGI/libdwarf40* style of memory allocation. In most cases it does not copy41* things to return to the client, so the client does not need42* to remember to free them. The remaining cases are handled43* below.44*/4546(void) dbg;4748if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK ||49alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_LOCDESC)50free(p);51else if (alloc_type == DW_DLA_ABBREV) {52ab = p;53STAILQ_FOREACH_SAFE(ad, &ab->ab_attrdef, ad_next, tad) {54STAILQ_REMOVE(&ab->ab_attrdef, ad, _Dwarf_AttrDef,55ad_next);56free(ad);57}58free(ab);59} else if (alloc_type == DW_DLA_DIE) {60die = p;61STAILQ_FOREACH_SAFE(at, &die->die_attr, at_next, tat) {62STAILQ_REMOVE(&die->die_attr, at,63_Dwarf_Attribute, at_next);64if (at->at_ld != NULL)65free(at->at_ld);66free(at);67}68if (die->die_attrarray)69free(die->die_attrarray);70free(die);71}72}7374void75dwarf_srclines_dealloc(Dwarf_Debug dbg, Dwarf_Line *linebuf,76Dwarf_Signed count)77{78/*79* In this libdwarf implementation, line information remains80* associated with the DIE for a compilation unit for the81* lifetime of the DIE. The client does not need to free82* the memory returned by `dwarf_srclines()`.83*/8485(void) dbg; (void) linebuf; (void) count;86}8788void89dwarf_ranges_dealloc(Dwarf_Debug dbg, Dwarf_Ranges *ranges,90Dwarf_Signed range_count)91{92/*93* In this libdwarf implementation, ranges information is94* kept by a STAILQ inside Dwarf_Debug object. The client95* does not need to free the memory returned by96* `dwarf_get_ranges()` or `dwarf_get_ranges_a()`.97*/9899(void) dbg; (void) ranges; (void) range_count;100}101102void103dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg, Dwarf_Cie *cie_list,104Dwarf_Signed cie_count, Dwarf_Fde *fde_list, Dwarf_Signed fde_count)105{106/*107* In this implementation, FDE and CIE information is managed108* as part of the Dwarf_Debug object. The client does not need109* to explicitly free these memory arenas.110*/111(void) dbg;112(void) cie_list;113(void) cie_count;114(void) fde_list;115(void) fde_count;116}117118119