summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric Bail <cedric.bail@free.fr>2019-09-14 10:16:56 -0700
committerCedric Bail <cedric.bail@free.fr>2019-09-17 10:24:03 -0700
commit20641126842f9e89147ee19d970b4dc6ecf44e60 (patch)
tree94d74d70bdbca85935b0ca3c9b57ff53a2073fbd
parentcce67afc38e90c4a6fef9c43572c52794d592906 (diff)
downloadefl-20641126842f9e89147ee19d970b4dc6ecf44e60.tar.gz
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
-rw-r--r--src/modules/eina/mp/chained_pool/eina_chained_mempool.c15
1 files 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 b32747ec4f..d44f0bf6cb 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)
{