diff --git a/src/memory_pool.c b/src/memory_pool.c index 87816cd7e..ea288c533 100644 --- a/src/memory_pool.c +++ b/src/memory_pool.c @@ -45,7 +45,9 @@ */ #include + #include +#include "debug.h" typedef struct node { struct node * next; @@ -79,6 +81,16 @@ void * memory_pool_get(memory_pool_t *pool){ void memory_pool_free(memory_pool_t *pool, void * block){ node_t *free_blocks = (node_t*) pool; node_t *node = (node_t*) block; + + // raise error and abort if node already in list + node_t * it; + for (it = free_blocks->next; it ; it = it->next){ + if (it == node) { + log_error("memory_pool_free: block %p freed twice for pool %p", block, pool); + return; + } + } + // add block as node to list node->next = free_blocks->next; free_blocks->next = node;