?????塢??????????????????????????

??????????????????????????????????????????pheap????????飬????????????????????????????????????????????struct pfree????

??????????????????????????????????pheap??????к??????????????????????????????????????????й?????

    clean = _pool_free(p?? _pool_heap_free?? (void *)ret);
    clean->heap = ret; /* for future use in finding used mem for pstrdup */
    _pool_cleanup_append(p?? clean);

????_pool_free??????鶨???????????г?????????μ???

static struct pfree *_pool_free(pool_t p?? pool_cleanup_t f?? void *arg)
{
    struct pfree *ret;
    while((ret = malloc(sizeof(struct pfree))) == NULL) sleep(1);
    ret->f = f;
    ret->arg = arg;
    ret->next = NULL;

    return ret;
}

??????????????????????sturct pfree??????????????struct pheap???????????г?????????????????????arg??heap???????struct pheap???????????????????????????????????????

????????????pool_cleanup_t??????????????????????????_pool_heap_free????????????????????飬??????????£?

static void _pool_heap_free(void *arg)
{
    struct pheap *h = (struct pheap *)arg;
    free(h->block);
    free(h);
}

??????????????????????????????????

?????????????????????????????飬??????????????????????????顧struct pfree?????????????????_pool_cleanup_append????????Щ??????

static void _pool_cleanup_append(pool_t p?? struct pfree *pf)
{
    struct pfree *cur;

    if(p->cleanup == NULL)
    {
        p->cleanup = pf;
        p->cleanup_tail = pf;
        return;
    }

    cur = p->cleanup_tail;
    cur->next = pf;
    p->cleanup_tail = pf;
}

??????????????????struct pfree??????????cleanup_tail??????β???????μ?cleanup_tail????????pfree????

??????????????????????malloc?????????????????????????£?

????1??????malloc???????飬???????struct pheap????

????2????struct pheap???????struct pfree????????struct pheap???????????????????

????3????struct pfree??????struct pool_sturct???????????????????????β??