From fb0162d7697e71f466ac9f9af501decfa0062a88 Mon Sep 17 00:00:00 2001 From: yuqing Date: Wed, 8 Jun 2016 18:30:14 +0800 Subject: [PATCH] check g_free_queue.head == NULL before free_queue_realloc() --- HISTORY | 3 ++- src/fast_task_queue.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/HISTORY b/HISTORY index 16bac36..3bce3fd 100644 --- a/HISTORY +++ b/HISTORY @@ -1,10 +1,11 @@ -Version 1.28 2016-06-06 +Version 1.28 2016-06-08 * id generator support extra bits * change inet_aton to inet_pton * connect by ip and connection pool support ipv6 * id generator in php extension support multi instance * add function http_parse_url_params + * check g_free_queue.head == NULL before free_queue_realloc() Version 1.27 2016-04-15 * add function fd_set_cloexec diff --git a/src/fast_task_queue.c b/src/fast_task_queue.c index 273de6a..6d1ba64 100644 --- a/src/fast_task_queue.c +++ b/src/fast_task_queue.c @@ -410,6 +410,8 @@ static int free_queue_realloc() struct fast_task_info *free_queue_pop() { struct fast_task_info *pTask; + int i; + if ((pTask=task_queue_pop(&g_free_queue)) != NULL) { return pTask; @@ -420,26 +422,34 @@ struct fast_task_info *free_queue_pop() return NULL; } - pthread_mutex_lock(&g_free_queue.lock); - if (g_free_queue.alloc_connections >= g_free_queue.max_connections) + for (i=0; i<10; i++) { - if (g_free_queue.head == NULL) + pthread_mutex_lock(&g_free_queue.lock); + if (g_free_queue.alloc_connections >= g_free_queue.max_connections) { - pthread_mutex_unlock(&g_free_queue.lock); - return NULL; + if (g_free_queue.head == NULL) + { + pthread_mutex_unlock(&g_free_queue.lock); + return NULL; + } } - } - else - { - if (free_queue_realloc() != 0) + else { - pthread_mutex_unlock(&g_free_queue.lock); - return NULL; + if (g_free_queue.head == NULL && free_queue_realloc() != 0) + { + pthread_mutex_unlock(&g_free_queue.lock); + return NULL; + } } - } - pthread_mutex_unlock(&g_free_queue.lock); + pthread_mutex_unlock(&g_free_queue.lock); - return task_queue_pop(&g_free_queue); + if ((pTask=task_queue_pop(&g_free_queue)) != NULL) + { + return pTask; + } + } + + return NULL; } static int _realloc_buffer(struct fast_task_info *pTask, const int new_size,