check for blocks being freed twice

This commit is contained in:
Matthias Ringwald 2015-04-11 22:05:44 +02:00
parent 5387db55b8
commit 065bf9df89

View File

@ -45,7 +45,9 @@
*/
#include <btstack/memory_pool.h>
#include <stddef.h>
#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;