diff options
| author | 彭宣正 <[email protected]> | 2021-06-02 15:49:24 +0800 |
|---|---|---|
| committer | 彭宣正 <[email protected]> | 2021-06-02 15:51:06 +0800 |
| commit | da3bc1db06ef3ecd2aa76ffe58e5b14e5828f3c7 (patch) | |
| tree | 070e78d0fdd69538271996e0a4c70741b86c6270 /src | |
| parent | 20e6f942cd8a45bd8846e90e6d2934f26b3a5303 (diff) | |
修复add_hos_info导致的segment faultv1.0.25
Diffstat (limited to 'src')
| -rw-r--r-- | src/hos_client.cpp | 4 | ||||
| -rw-r--r-- | src/hos_hash.cpp | 28 |
2 files changed, 25 insertions, 7 deletions
diff --git a/src/hos_client.cpp b/src/hos_client.cpp index df298982..49d73c77 100644 --- a/src/hos_client.cpp +++ b/src/hos_client.cpp @@ -221,6 +221,7 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum) if (fd_info) { fd_info = (size_t (*) [MAX_HOS_CLIENT_FD_NUM + 1])realloc(fd_info, thread_sum * sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1])); + memset(&fd_info[client->thread_sum], 0, (thread_sum - client->thread_sum) * sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1])); }else { fd_info = (size_t (*) [MAX_HOS_CLIENT_FD_NUM + 1])calloc(thread_sum, sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1])); @@ -743,7 +744,7 @@ static void *hos_fd_manage(void *ptr) int hos_open_fd(hos_client_handle handle, const char *bucket, const char *object, put_finished_callback callback, void *userdata, size_t thread_id, int mode) { - if ((handle == NULL) || (bucket == NULL) || (object == NULL) || (thread_id > handle->thread_sum)) + if ((handle == NULL) || (bucket == NULL) || (object == NULL) || (thread_id > handle->thread_sum) || strlen(bucket) == 0 || strlen(object) == 0) { return HOS_PARAMETER_ERROR; } @@ -760,6 +761,7 @@ int hos_open_fd(hos_client_handle handle, const char *bucket, const char *object #if 1 if (handle->fd_thread == 0) { + std::lock_guard<std::mutex> locker(m_client_lock); handle->fd_thread_status = 0; pthread_create(&handle->fd_thread, NULL, hos_fd_manage, handle); } diff --git a/src/hos_hash.cpp b/src/hos_hash.cpp index bf54005d..a6c6d51d 100644 --- a/src/hos_hash.cpp +++ b/src/hos_hash.cpp @@ -13,18 +13,30 @@ void add_hos_info(hos_info_t **handle, hos_info_t *input) { value = (hos_info_t *)malloc(sizeof(hos_info_t)); memcpy(value, input, sizeof(hos_info_t)); - value->object = (char *)malloc(strlen(input->object) + 1); - value->bucket = (char *)malloc(strlen(input->bucket) + 1); - memcpy(value->bucket, input->bucket, strlen(input->bucket) + 1); - memcpy(value->object, input->object, strlen(input->object) + 1); + value->object = (char *)calloc(1, strlen(input->object) + 1); + value->bucket = (char *)calloc(1, strlen(input->bucket) + 1); + memcpy(value->bucket, input->bucket, strlen(input->bucket)); + memcpy(value->object, input->object, strlen(input->object)); HASH_ADD_INT(*handle, fd, value); } else { value->mode = input->mode; value->handle = input->handle; - memcpy(value->bucket, input->bucket, strlen(input->bucket) + 1); - memcpy(value->object, input->object, strlen(input->object) + 1); + if (value->object != NULL) + { + free(value->object); + value->object = NULL; + } + if (value->bucket != NULL) + { + free(value->bucket); + value->bucket = NULL; + } + value->object = (char *)calloc(1, strlen(input->object) + 1); + value->bucket = (char *)calloc(1, strlen(input->bucket) + 1); + memcpy(value->bucket, input->bucket, strlen(input->bucket)); + memcpy(value->object, input->object, strlen(input->object)); value->callback = input->callback; value->userdata = input->userdata; value->cache = input->cache; @@ -55,10 +67,12 @@ void delete_info_by_fd(hos_info_t **handle, size_t fd) if (value->bucket) { free(value->bucket); + value->bucket = NULL; } if (value->object) { free(value->object); + value->object = NULL; } HASH_DEL(*handle, value); free(value); @@ -73,10 +87,12 @@ void delete_all(hos_info_t **handle) if (current->bucket) { free(current->bucket); + current->bucket = NULL; } if (current->object) { free(current->object); + current->object = NULL; } HASH_DEL(*handle, current); free(current); |
