cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=20641126842f9e89147ee19d970b4dc6ecf44e60

commit 20641126842f9e89147ee19d970b4dc6ecf44e60
Author: Cedric Bail <[email protected]>
Date:   Sat Sep 14 10:16:56 2019 -0700

    eina: fix eina_mempool_from to not report pointer that have never been 
allocated as allocated.
    
    Reviewed-by: Mike Blumenkrantz <[email protected]>
    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 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)
      {

-- 


Reply via email to