mirror of
https://github.com/bluekitchen/btstack.git
synced 2024-12-29 09:26:08 +00:00
check for blocks being freed twice
This commit is contained in:
parent
5387db55b8
commit
065bf9df89
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user