From 6083b631de099d6dab9e2949195c3a437fd10e14 Mon Sep 17 00:00:00 2001 From: Cedric Bail Date: Sat, 14 Sep 2019 10:16:56 -0700 Subject: [PATCH] eina: fix eina_mempool_from to not report pointer that have never been allocated as allocated. Reviewed-by: Mike Blumenkrantz Differential Revision: https://phab.enlightenment.org/D9938 --- src/modules/eina/mp/chained_pool/eina_chained_mempool.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/modules/eina/mp/chained_pool/eina_chained_mempool.c b/src/modules/eina/mp/chained_pool/eina_chained_mempool.c index b32747e..d44f0bf 100644 --- a/src/modules/eina/mp/chained_pool/eina_chained_mempool.c +++ b/src/modules/eina/mp/chained_pool/eina_chained_mempool.c @@ -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) { -- 2.7.4