Example #1
0
/*
 * Free tail arenas linked after head, which may not be the true list head.
 * Reset pool->current to point to head in case it pointed at a tail arena.
 */
static void FreeArenaList(ArenaPool *pool, Arena *head, bool reallyFree)
{
    Arena **ap, *a;

    ap = &head->next;
    a = *ap;
    if (!a)
        return;

#ifdef DEBUG
    do {
        ASSERT(a->base <= a->avail && a->avail <= a->limit);
        a->avail = a->base;
        CLEAR_UNUSED(a);
    } while ((a = a->next) != 0);
    a = *ap;
#endif

    if (freelist_count >= FREELIST_MAX)
        reallyFree = true;
        
    if (reallyFree) {
        do {
            *ap = a->next;
            CLEAR_ARENA(a);
#ifdef DEBUG_ARENA_MALLOC
            if (a) {
                i--;
                OWB_PRINTF("Free: %d\n", i);
            }
#endif
            fastFree(a); a = 0;
        } while ((a = *ap) != 0);
    } else {
        /* Insert the whole arena chain at the front of the freelist. */
        do {
            ap = &(*ap)->next;
            freelist_count++;
        } while (*ap);
        *ap = arena_freelist;
        arena_freelist = a;
        head->next = 0;
    }
    pool->current = head;
}
Example #2
0
File: arena.cpp Project: KDE/khtml
/*
 * Free tail arenas linked after head, which may not be the true list head.
 * Reset pool->current to point to head in case it pointed at a tail arena.
 */
static void FreeArenaList(ArenaPool *pool, Arena *head, bool reallyFree)
{
    Arena **ap, *a;

    ap = &head->next;
    a = *ap;
    if (!a) {
        return;
    }

#ifdef DEBUG_ARENA_MALLOC
    printf("****** Freeing arena pool. Total allocated memory: %d\n", pool->cumul);

    do {
        assert(a->base <= a->avail && a->avail <= a->limit);
        a->avail = a->base;
        CLEAR_UNUSED(a);
    } while ((a = a->next) != 0);
    a = *ap;
#endif

    if (freelist_count >= FREELIST_MAX) {
        reallyFree = true;
    }

    if (reallyFree) {
        do {
            *ap = a->next;
            VALGRIND_DESTROY_MEMPOOL(a->base);
            CLEAR_ARENA(a);
#ifdef DEBUG_ARENA_MALLOC
            if (a) {
                i--;
                printf("Free: %d\n", i);
            }
#endif
            free(a); a = 0;
        } while ((a = *ap) != 0);
    } else {
        /* Insert as much of the arena chain as we can hold at the front of the freelist. */
        do {
            ap = &(*ap)->next;
            freelist_count++;
        } while (*ap && freelist_count < FREELIST_MAX);

        /* Get rid of excess */
        if (*ap) {
            Arena *xa, *n;
            for (xa = *ap; xa; xa = n) {
                VALGRIND_DESTROY_MEMPOOL(xa->base);
                n = xa->next;
#ifdef DEBUG_ARENA_MALLOC
                i--;
                printf("Free: %d\n", i);
#endif
                CLEAR_ARENA(xa);
                free(xa);
            }
        }
        *ap = arena_freelist;
        arena_freelist = a;
        head->next = 0;
    }
    pool->current = head;
}