--- lbbs/src/memory_pool.c 2025/11/11 00:28:05 1.9 +++ lbbs/src/memory_pool.c 2026/01/06 13:59:21 1.12 @@ -3,7 +3,7 @@ * memory_pool * - memory pool * - * Copyright (C) 2004-2025 Leaflet + * Copyright (C) 2004-2026 Leaflet */ #ifdef HAVE_CONFIG_H @@ -21,14 +21,14 @@ MEMORY_POOL *memory_pool_init(size_t nod if (node_size < sizeof(void *)) { - log_error("Error: node_size < sizeof(void *)\n"); + log_error("Error: node_size < sizeof(void *)"); return NULL; } p_pool = malloc(sizeof(MEMORY_POOL)); if (p_pool == NULL) { - log_error("malloc(MEMORY_POOL) error: OOM\n"); + log_error("malloc(MEMORY_POOL) error: OOM"); return NULL; } @@ -41,7 +41,7 @@ MEMORY_POOL *memory_pool_init(size_t nod p_pool->p_chunks = malloc(sizeof(void *) * (size_t)chunk_count_limit); if (p_pool->p_chunks == NULL) { - log_error("malloc(sizeof(void *) * %d) error: OOM\n", chunk_count_limit); + log_error("malloc(sizeof(void *) * %d) error: OOM", chunk_count_limit); free(p_pool); return NULL; } @@ -62,7 +62,7 @@ void memory_pool_cleanup(MEMORY_POOL *p_ if (p_pool->node_count_allocated > 0) { - log_error("Still have %d in-use nodes\n", p_pool->node_count_allocated); + log_error("Still have %d in-use nodes", p_pool->node_count_allocated); } while (p_pool->chunk_count > 0) @@ -80,16 +80,19 @@ inline static void *memory_pool_add_chun void *p_chunk; void *p_node; size_t i; + size_t chunk_size; if (p_pool->chunk_count >= p_pool->chunk_count_limit) { - log_error("Chunk count limit %d reached\n", p_pool->chunk_count); + log_error("Chunk count limit %d reached", p_pool->chunk_count); return NULL; } - p_chunk = malloc(p_pool->node_size * p_pool->node_count_per_chunk); + + chunk_size = p_pool->node_size * p_pool->node_count_per_chunk; + p_chunk = malloc(chunk_size); if (p_chunk == NULL) { - log_error("malloc(%d * %d) error: OOM\n", p_pool->node_size, p_pool->node_count_per_chunk); + log_error("malloc(%zu) error: OOM", chunk_size); return NULL; } @@ -117,13 +120,13 @@ void *memory_pool_alloc(MEMORY_POOL *p_p if (p_pool == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return NULL; } if (p_pool->p_free == NULL && memory_pool_add_chunk(p_pool) == NULL) { - log_error("Add chunk error\n"); + log_error("Add chunk error"); return NULL; } @@ -140,7 +143,7 @@ void memory_pool_free(MEMORY_POOL *p_poo { if (p_pool == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return; } @@ -163,7 +166,7 @@ int memory_pool_check_node(MEMORY_POOL * if (p_pool == NULL || p_node == NULL) { - log_error("NULL pointer error\n"); + log_error("NULL pointer error"); return -1; } @@ -179,13 +182,13 @@ int memory_pool_check_node(MEMORY_POOL * } else { - log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)\n", - i, p_node >= p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size); + log_error("Address of node (%p) is not aligned with border of chunk %d [%p, %p)", + p_node, i, p_pool->p_chunks[i], (char *)(p_pool->p_chunks[i]) + chunk_size); return -3; } } } - log_error("Address of node is not in range of chunks\n"); + log_error("Address of node is not in range of chunks"); return -2; }