From 590aa8d3a006ece9038fe4fb5d2ce0480ad8f980 Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Sat, 28 Mar 2020 23:12:02 +0800 Subject: [PATCH] bugfixed: call fast_mblock_destroy in common_blocked_queue_destroy --- HISTORY | 3 ++- src/common_blocked_queue.c | 12 +++++++----- src/fast_allocator.c | 8 ++++---- src/fast_allocator.h | 12 +++++++++--- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/HISTORY b/HISTORY index 148e8fa..eafccdc 100644 --- a/HISTORY +++ b/HISTORY @@ -1,5 +1,5 @@ -Version 1.44 2020-03-26 +Version 1.44 2020-03-28 * add test file src/tests/test_pthread_lock.c * add uniq_skiplist.[hc] * add function split_string_ex @@ -23,6 +23,7 @@ Version 1.44 2020-03-26 * sched_add_entries use temp ScheduleArray for rare case * add function common_blocked_queue_return_nodes * add functions getIpAndPort and getPeerIpAndPort + * bugfixed: call fast_mblock_destroy in common_blocked_queue_destroy Version 1.43 2019-12-25 * replace function call system to getExecResult, diff --git a/src/common_blocked_queue.c b/src/common_blocked_queue.c index ab9a641..5bd5105 100644 --- a/src/common_blocked_queue.c +++ b/src/common_blocked_queue.c @@ -31,9 +31,10 @@ int common_blocked_queue_init_ex(struct common_blocked_queue *queue, return result; } - if ((result=fast_mblock_init_ex(&queue->mblock, - sizeof(struct common_blocked_node), - alloc_elements_once, NULL, NULL, false)) != 0) + if ((result=fast_mblock_init_ex2(&queue->mblock, + "queue_node", sizeof(struct common_blocked_node), + alloc_elements_once, NULL, NULL, false, + NULL, NULL, NULL)) != 0) { return result; } @@ -46,8 +47,9 @@ int common_blocked_queue_init_ex(struct common_blocked_queue *queue, void common_blocked_queue_destroy(struct common_blocked_queue *queue) { - pthread_cond_destroy(&(queue->cond)); - pthread_mutex_destroy(&(queue->lock)); + pthread_cond_destroy(&queue->cond); + pthread_mutex_destroy(&queue->lock); + fast_mblock_destroy(&queue->mblock); } int common_blocked_queue_push_ex(struct common_blocked_queue *queue, diff --git a/src/fast_allocator.c b/src/fast_allocator.c index 8fb1e65..506efc0 100644 --- a/src/fast_allocator.c +++ b/src/fast_allocator.c @@ -495,17 +495,17 @@ void fast_allocator_free(struct fast_allocator_context *acontext, void *ptr) } } -char *fast_allocator_strdup_ex(struct fast_allocator_context *acontext, +char *fast_allocator_memdup(struct fast_allocator_context *acontext, const char *src, const int len) { char *dest; - dest = (char *)fast_allocator_alloc(acontext, len + 1); + dest = (char *)fast_allocator_alloc(acontext, len); if (dest == NULL) { logError("file: "__FILE__", line: %d, " - "malloc %d bytes fail", __LINE__, len + 1); + "malloc %d bytes fail", __LINE__, len); return NULL; } - memcpy(dest, src, len + 1); + memcpy(dest, src, len); return dest; } diff --git a/src/fast_allocator.h b/src/fast_allocator.h index 5338565..43df690 100644 --- a/src/fast_allocator.h +++ b/src/fast_allocator.h @@ -139,19 +139,25 @@ return error no, 0 for success, != 0 fail int fast_allocator_retry_reclaim(struct fast_allocator_context *acontext, int64_t *total_reclaim_bytes); -char *fast_allocator_strdup_ex(struct fast_allocator_context *acontext, +char *fast_allocator_memdup(struct fast_allocator_context *acontext, const char *src, const int len); +static inline char *fast_allocator_strdup_ex(struct fast_allocator_context * + acontext, const char *src, const int len) +{ + return fast_allocator_memdup(acontext, src, len + 1); +} + static inline char *fast_allocator_strdup(struct fast_allocator_context * acontext, const char *src) { - return fast_allocator_strdup_ex(acontext, src, strlen(src)); + return fast_allocator_memdup(acontext, src, strlen(src) + 1); } static inline int fast_allocator_alloc_string_ex(struct fast_allocator_context *acontext, string_t *dest, const char *src, const int len) { - dest->str = fast_allocator_strdup_ex(acontext, src, len); + dest->str = fast_allocator_memdup(acontext, src, len); dest->len = len; return dest->str != NULL ? 0 : ENOMEM; }