mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-01 09:08:06 +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 <btstack/memory_pool.h>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
typedef struct node {
|
typedef struct node {
|
||||||
struct node * next;
|
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){
|
void memory_pool_free(memory_pool_t *pool, void * block){
|
||||||
node_t *free_blocks = (node_t*) pool;
|
node_t *free_blocks = (node_t*) pool;
|
||||||
node_t *node = (node_t*) block;
|
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
|
// add block as node to list
|
||||||
node->next = free_blocks->next;
|
node->next = free_blocks->next;
|
||||||
free_blocks->next = node;
|
free_blocks->next = node;
|
||||||
|
Loading…
Reference in New Issue
Block a user