mpool icon indicating copy to clipboard operation
mpool copied to clipboard

mpool_create leaks

Open simon-p-r opened this issue 7 years ago • 2 comments

On failure there is no cleanup of allocted memory on line 59 and 64 of mpool.c, I can do a PR if you will merge in.

simon-p-r avatar Dec 09 '18 20:12 simon-p-r

in line 58, pool->usiz = 0; should be pool->usiz = mpool_align(siz);

 45 /**
 46  * allocate memory from memory pool
 47  */
 48 void *mpool_alloc(size_t siz, mpool_t *pool) {
 49     mpool_pool_t **p = &pool->mpool;
 50     mpool_pool_t *pp = *p;
 51     size_t usiz = mpool_align(pool->usiz + siz);
 52     size_t msiz = pool->msiz;
 53     void     *d = pool->begin;
 54     if (usiz > msiz) {
 55         if (!mpool_extend(pp, usiz * 2 + 1, pool)) {
 56             return NULL;
 57         }
 58         pool->usiz = 0;
 59         pool->msiz = usiz * 2;
 60         d = pool->begin;
 61         pool->begin += mpool_align(siz);
 62         *p = pp->next;
 63     } else {
 64         pool->usiz = usiz;
 65         pool->begin += mpool_align(siz);
 66     }
 67
 68     return d;
 69 }

GuohuaZhuang avatar Feb 14 '19 08:02 GuohuaZhuang

there is no "mpool_free" function

lijk8890 avatar May 06 '19 09:05 lijk8890