2 * Copyright (c) 2007 John Birrell (jb@freebsd.org)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include "_libdwarf.h"
29 ELFTC_VCSID("$Id: dwarf_dealloc.c 2073 2011-10-27 03:30:47Z jkoshy $");
32 dwarf_dealloc(Dwarf_Debug dbg, Dwarf_Ptr p, Dwarf_Unsigned alloc_type)
35 Dwarf_AttrDef ad, tad;
36 Dwarf_Attribute at, tat;
40 * This libdwarf implementation does not use the SGI/libdwarf
41 * style of memory allocation. In most cases it does not copy
42 * things to return to the client, so the client does not need
43 * to remember to free them. The remaining cases are handled
49 if (alloc_type == DW_DLA_LIST || alloc_type == DW_DLA_FRAME_BLOCK ||
50 alloc_type == DW_DLA_LOC_BLOCK || alloc_type == DW_DLA_LOCDESC)
52 else if (alloc_type == DW_DLA_ABBREV) {
54 STAILQ_FOREACH_SAFE(ad, &ab->ab_attrdef, ad_next, tad) {
55 STAILQ_REMOVE(&ab->ab_attrdef, ad, _Dwarf_AttrDef,
60 } else if (alloc_type == DW_DLA_DIE) {
62 STAILQ_FOREACH_SAFE(at, &die->die_attr, at_next, tat) {
63 STAILQ_REMOVE(&die->die_attr, at,
64 _Dwarf_Attribute, at_next);
65 if (at->at_ld != NULL)
69 if (die->die_attrarray)
70 free(die->die_attrarray);
76 dwarf_srclines_dealloc(Dwarf_Debug dbg, Dwarf_Line *linebuf,
80 * In this libdwarf implementation, line information remains
81 * associated with the DIE for a compilation unit for the
82 * lifetime of the DIE. The client does not need to free
83 * the memory returned by `dwarf_srclines()`.
86 (void) dbg; (void) linebuf; (void) count;
90 dwarf_ranges_dealloc(Dwarf_Debug dbg, Dwarf_Ranges *ranges,
91 Dwarf_Signed range_count)
94 * In this libdwarf implementation, ranges information is
95 * kept by a STAILQ inside Dwarf_Debug object. The client
96 * does not need to free the memory returned by
97 * `dwarf_get_ranges()` or `dwarf_get_ranges_a()`.
100 (void) dbg; (void) ranges; (void) range_count;
104 dwarf_fde_cie_list_dealloc(Dwarf_Debug dbg, Dwarf_Cie *cie_list,
105 Dwarf_Signed cie_count, Dwarf_Fde *fde_list, Dwarf_Signed fde_count)
108 * In this implementation, FDE and CIE information is managed
109 * as part of the Dwarf_Debug object. The client does not need
110 * to explicitly free these memory arenas.