From fafbbb557e533bd4ac428ba2f4572169f2a7cd7e Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Wed, 2 Aug 2023 14:53:27 +0800 Subject: [PATCH] bugfixed: array_allocator_alloc MUST init the array --- HISTORY | 3 +++ src/array_allocator.c | 7 ++++++- src/array_allocator.h | 1 - src/fast_mblock.c | 2 ++ src/sorted_queue.c | 2 -- 5 files changed, 11 insertions(+), 4 deletions(-) diff --git a/HISTORY b/HISTORY index 0a1f337..0750d4a 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.69 2023-08-02 + * bugfixed: array_allocator_alloc MUST init the array + Version 1.68 2023-07-05 * sorted_queue.[hc]: pop_compare_func support argument diff --git a/src/array_allocator.c b/src/array_allocator.c index ff060a5..a468d53 100644 --- a/src/array_allocator.c +++ b/src/array_allocator.c @@ -58,6 +58,7 @@ VoidArray *array_allocator_alloc(ArrayAllocatorContext *ctx, { int alloc; int bytes; + VoidArray *array; if (target_count <= ctx->min_count) { alloc = ctx->min_count; @@ -71,7 +72,11 @@ VoidArray *array_allocator_alloc(ArrayAllocatorContext *ctx, } bytes = sizeof(VoidArray) + alloc * ctx->element_size; - return (VoidArray *)fast_allocator_alloc(&ctx->allocator, bytes); + if ((array=fast_allocator_alloc(&ctx->allocator, bytes)) != NULL) { + array->alloc = alloc; + array->count = 0; + } + return array; } VoidArray *array_allocator_realloc(ArrayAllocatorContext *ctx, diff --git a/src/array_allocator.h b/src/array_allocator.h index fa6225f..238dab0 100644 --- a/src/array_allocator.h +++ b/src/array_allocator.h @@ -78,7 +78,6 @@ extern "C" { static inline void array_allocator_free(ArrayAllocatorContext *ctx, VoidArray *array) { - array->count = 0; fast_allocator_free(&ctx->allocator, array); } diff --git a/src/fast_mblock.c b/src/fast_mblock.c index 11499d4..b36077b 100644 --- a/src/fast_mblock.c +++ b/src/fast_mblock.c @@ -1163,6 +1163,7 @@ OUTER: } + /* { bool old_need_lock; old_need_lock = mblock->need_lock; @@ -1173,6 +1174,7 @@ OUTER: mblock, *reclaim_count, fast_mblock_free_count(mblock)); mblock->need_lock = old_need_lock; } + */ *ppFreelist = freelist; return (freelist != NULL ? 0 : ENOENT); diff --git a/src/sorted_queue.c b/src/sorted_queue.c index 0381e9b..373cbc6 100644 --- a/src/sorted_queue.c +++ b/src/sorted_queue.c @@ -46,7 +46,6 @@ void sorted_queue_push_ex(struct sorted_queue *sq, void *data, bool *notify) { struct fc_list_head *dlink; struct fc_list_head *current; - int count = 0; dlink = FC_SORTED_QUEUE_DLINK_PTR(sq, data); PTHREAD_MUTEX_LOCK(&sq->lcp.lock); @@ -70,7 +69,6 @@ void sorted_queue_push_ex(struct sorted_queue *sq, void *data, bool *notify) sq, current)) < 0) { current = current->prev; - ++count; } fc_list_add_after(dlink, current); *notify = false;