summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author彭宣正 <[email protected]>2021-04-16 17:07:15 +0800
committer彭宣正 <[email protected]>2021-04-16 17:07:15 +0800
commit20e6f942cd8a45bd8846e90e6d2934f26b3a5303 (patch)
tree7d2cf5cf968953d4de80431d2518a5f0b893919d
parent82dc6b00e7632ccadf315030926c1eaa51ecb3fb (diff)
🐞fix(hos_set_thread_sum): 修复fd_info引起的内存错误v1.0.24
-rw-r--r--src/hos_client.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/hos_client.cpp b/src/hos_client.cpp
index 9e56bf2e..df298982 100644
--- a/src/hos_client.cpp
+++ b/src/hos_client.cpp
@@ -204,10 +204,6 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
return;
}
- for (size_t i = 0; i < thread_sum; i++)
- {
- fd_info[i][0] = 65533;
- }
if (hos_cache)
{
hos_cache = (size_t *)realloc(hos_cache, thread_sum * sizeof(size_t));
@@ -221,6 +217,7 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
{
hash_hos_info = (hos_info_t **)calloc(thread_sum, sizeof(hos_info_t*));
}
+
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]));
@@ -228,6 +225,12 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
{
fd_info = (size_t (*) [MAX_HOS_CLIENT_FD_NUM + 1])calloc(thread_sum, sizeof(size_t [MAX_HOS_CLIENT_FD_NUM + 1]));
}
+
+ for (size_t i = 0; i < thread_sum; i++)
+ {
+ fd_info[i][0] = 65533;
+ }
+
client->thread_sum = thread_sum;
return ;
}