Example #1
0
/*
    This function is used to deallocate a region of memory
    that was obtained by a call to _dwarf_get_alloc.  Note
    that though dwarf_dealloc() is a public function,
    _dwarf_get_alloc() isn't.

    For lists, typically arrays of pointers, it is assumed
    that the space was allocated by a direct call to malloc,
    and so a straight free() is done.  This is also the case
    for variable length blocks such as DW_DLA_FRAME_BLOCK
    and DW_DLA_LOC_BLOCK and DW_DLA_RANGES.

    For strings, the pointer might point to a string in
    .debug_info or .debug_string.  After this is checked,
    and if found not to be the case, a free() is done,
    again on the assumption that a malloc was used to
    obtain the space.

    This function does not return anything.
*/
void
dwarf_dealloc(Dwarf_Debug dbg,
    Dwarf_Ptr space, Dwarf_Unsigned alloc_type)
{
    unsigned int type = alloc_type;
    char * malloc_addr = (char *)space - DW_RESERVE;

    if (space == NULL) {
        return;
    }
    if (dbg == NULL) {
        /*  App error, or an app that failed to succeed in a
            dwarf_init() call. */
        return;
    }
    if (type >= ALLOC_AREA_INDEX_TABLE_MAX) {
        /* internal or user app error */
        return;
    }

    if (type == DW_DLA_STRING && string_is_in_debug_section(dbg,space)) {
        /*  A string pointer may point into .debug_info or .debug_string etc.
            So must not be freed.  And strings have no need of a
            specialdestructor().
            Mostly a historical mistake here. */
        return;
    }

    if (alloc_instance_basics[type].specialdestructor) {
        alloc_instance_basics[type].specialdestructor(space);
    }
    {
        /*  The 'space' pointer we get points after the reserve space.
            The key and address to free are just a few bytes before
            'space'. */
        void *key = space;
        dwarf_tdelete(key,&dbg->de_alloc_tree,simple_compare_function);
        /*  If dwarf_tdelete returns NULL it might mean
            a) tree is empty.
            b) If hashsearch, then a single chain might now be empty,
                so we do not know of a 'parent node'.
            c) We did not find that key, we did nothing.

            In any case, we simply don't worry about it.
            Not Supposed To Happen. */

        free(malloc_addr);
        return;
    }
}
Example #2
0
/*  For tfind and tdelete one can use static data and take its address
    for mt instead of using malloc/free.
*/
static int
deleteonebypointer(void **tree, unsigned addr,int ct)
{
    struct example_tentry *mt = 0;
    struct example_tentry *re3 = 0;
    void *r = 0;
    int err=0;

    mt = make_example_tentry(addr,0);
    r = dwarf_tfind(mt,(void *const*)tree,mt_compare_func);
    if (r) {
        re3 = *(struct example_tentry **)r;
        dwarf_tdelete(mt,tree,mt_compare_func);
        mt_free_func(mt);
        mt_free_func(re3);
    } else {
        printf("deleteonebypointer could not find rec %d ! error! addr"
            " 0x%lx\n",
            ct,(unsigned long)addr);
        mt_free_func(mt);
        err = 1;
    }
    return err;
}
Example #3
0
static int
deletebyvalue(void **tree, unsigned  addr,int ct)
{
    void *r = 0;
    int err=0;

    VALTYPE newval = addr;
    /* We are not mallocing, so nothing to free he tree holds simple values for us. */
    r = dwarf_tfind((void *)newval,(void *const*)tree,value_compare_func);
    if (r) {
        void *r2 = dwarf_tdelete((void *)newval,tree,value_compare_func);
        if(r2) {
            /* tdelete returned parent */
        } else {
            /* tdelete returned NULL, tree now empty */
        }
    } else {
        printf("deletebyvalue action %d could not find rec! error!"
            " addr 0x%x\n",
            addr,ct);
        err = 1;
    }
    return err;
}
Example #4
0
/* The dodump flag is so we can distinguish binarysearch actions
   from the binarysearch with eppinger mods easily in the test output.
   The difference is slight and not significant,
   but the difference is what we look for when we look.
*/
static int
delrecsbypointer(int max,int findexpected, void **tree,const enum insertorder order,int dodump)
{
    int indx = 0;
    for (indx = 0; indx < max; indx++) {
        struct example_tentry *mt = 0;
        struct example_tentry *re3 = 0;
        void *r = 0;

        int i = 0;

        i = get_record_id(order,indx);
        printf("delrec %d\n",i);
        mt = make_example_tentry(i,0);
        r = dwarf_tfind(mt,(void *const*)tree,mt_compare_func);
        if (r) {
            /*  This is what tdelete will delete.
                tdelete just removes the reference from
                the tree, it does not actually delete
                the memory for the entry itself.
                In fact there is no way to know for sure
                what was done just given the return
                from tdelete.  You just just assume the delete
                worked and use the tfind result to delete
                your contents if you want to.*/
            re3 = *(struct example_tentry **)r;
            if(indx < findexpected) {
                ;
            } else {
                mt_free_func(mt);
                printf("FAIL delrecsbypointer should not have found record to delete for %d\n",i);
                return 1;
            }
            r = dwarf_tdelete(mt,tree,mt_compare_func);
            if (! *tree) {
                printf("tree itself now empty\n");
            }
            /* We don't want the 'test' node left around. */
            if(r) {
                /*  If the node deleted was root, r
                    is really the new root, not the parent.
                    Or r is non-null but bogus.
                    (so don't print).
                    */
                printf("tdelete returned parent or something.\n");
            } else {
                printf("tdelete returned NULL, tree now empty.\n");
#ifdef HASHSEARCH
                printf("Only really means some hash chain is now empty.\n");
#endif /* HASHSEARCH */
            }
            mt_free_func(mt);
            mt_free_func(re3);
        } else {
            if(indx >= findexpected) {
                ;
            } else {
                mt_free_func(mt);
                printf("FAIL delrecsbypointer should have found record to delete for %d\n",i);
                return 1;
            }
            /* There is no node like this to delete. */
            /* We don't want the 'test' node left around. */
            mt_free_func(mt);
        }
        if (dodump) {
            dwarf_tdump( *tree,mt_keyprint,"In Delrecs");
        }
        dwarf_twalk( *tree,walk_entry);
    }
    return 0;
}