eina: fix eina_mempool_from to not report pointer that have never been allocated as allocated.

Reviewed-by: Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
Differential Revision: https://phab.enlightenment.org/D9938
This commit is contained in:
Cedric Bail 2019-09-14 10:16:56 -07:00
parent cce67afc38
commit 2064112684
1 changed files with 12 additions and 3 deletions

View File

@ -189,7 +189,7 @@ _eina_chained_mempool_alloc_in(Chained_Mempool *pool, Chained_Pool *p)
mem = p->last;
p->last += pool->item_alloc;
if (p->last >= p->limit)
p->last = NULL;
p->last = NULL;
}
else
{
@ -199,11 +199,11 @@ _eina_chained_mempool_alloc_in(Chained_Mempool *pool, Chained_Pool *p)
// Request a free pointer
mem = eina_trash_pop(&p->base);
}
// move to end - it just filled up
if (!p->base && !p->last)
pool->first = eina_inlist_demote(pool->first, EINA_INLIST_GET(p));
p->usage++;
pool->usage++;
@ -411,6 +411,15 @@ eina_chained_mempool_from(void *data, void *ptr)
goto end;
}
// is the pointer in the allocated zone of the mempool
if (p->last != NULL && ((unsigned char *)ptr >= p->last))
{
#ifdef DEBUG
ERR("%p has not been allocated yet from %p pool of %p '%s' Chained_Mempool.", ptr, p, pool, pool->name);
#endif
goto end;
}
// is it really a pointer returned by malloc
if ((((unsigned char *)ptr) - (unsigned char *)(p + 1)) % pool->item_alloc)
{