bugfixed: call fast_mblock_destroy in common_blocked_queue_destroy

pull/37/head
YuQing 2020-03-28 23:12:02 +08:00
parent 2df796589c
commit 590aa8d3a0
4 changed files with 22 additions and 13 deletions

View File

@ -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 test file src/tests/test_pthread_lock.c
* add uniq_skiplist.[hc] * add uniq_skiplist.[hc]
* add function split_string_ex * add function split_string_ex
@ -23,6 +23,7 @@ Version 1.44 2020-03-26
* sched_add_entries use temp ScheduleArray for rare case * sched_add_entries use temp ScheduleArray for rare case
* add function common_blocked_queue_return_nodes * add function common_blocked_queue_return_nodes
* add functions getIpAndPort and getPeerIpAndPort * add functions getIpAndPort and getPeerIpAndPort
* bugfixed: call fast_mblock_destroy in common_blocked_queue_destroy
Version 1.43 2019-12-25 Version 1.43 2019-12-25
* replace function call system to getExecResult, * replace function call system to getExecResult,

View File

@ -31,9 +31,10 @@ int common_blocked_queue_init_ex(struct common_blocked_queue *queue,
return result; return result;
} }
if ((result=fast_mblock_init_ex(&queue->mblock, if ((result=fast_mblock_init_ex2(&queue->mblock,
sizeof(struct common_blocked_node), "queue_node", sizeof(struct common_blocked_node),
alloc_elements_once, NULL, NULL, false)) != 0) alloc_elements_once, NULL, NULL, false,
NULL, NULL, NULL)) != 0)
{ {
return result; 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) void common_blocked_queue_destroy(struct common_blocked_queue *queue)
{ {
pthread_cond_destroy(&(queue->cond)); pthread_cond_destroy(&queue->cond);
pthread_mutex_destroy(&(queue->lock)); pthread_mutex_destroy(&queue->lock);
fast_mblock_destroy(&queue->mblock);
} }
int common_blocked_queue_push_ex(struct common_blocked_queue *queue, int common_blocked_queue_push_ex(struct common_blocked_queue *queue,

View File

@ -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) const char *src, const int len)
{ {
char *dest; char *dest;
dest = (char *)fast_allocator_alloc(acontext, len + 1); dest = (char *)fast_allocator_alloc(acontext, len);
if (dest == NULL) { if (dest == NULL) {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
"malloc %d bytes fail", __LINE__, len + 1); "malloc %d bytes fail", __LINE__, len);
return NULL; return NULL;
} }
memcpy(dest, src, len + 1); memcpy(dest, src, len);
return dest; return dest;
} }

View File

@ -139,19 +139,25 @@ return error no, 0 for success, != 0 fail
int fast_allocator_retry_reclaim(struct fast_allocator_context *acontext, int fast_allocator_retry_reclaim(struct fast_allocator_context *acontext,
int64_t *total_reclaim_bytes); 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); 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 * static inline char *fast_allocator_strdup(struct fast_allocator_context *
acontext, const char *src) 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 static inline int fast_allocator_alloc_string_ex(struct fast_allocator_context
*acontext, string_t *dest, const char *src, const int len) *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; dest->len = len;
return dest->str != NULL ? 0 : ENOMEM; return dest->str != NULL ? 0 : ENOMEM;
} }