🐞fix(hos_set_thread_sum): 修复fd_info引起的内存错误

This commit is contained in:
彭宣正
2021-04-16 17:07:15 +08:00
parent 82dc6b00e7
commit 20e6f942cd

View File

@@ -204,10 +204,6 @@ void hos_set_thread_sum(hos_client_handle client, size_t thread_sum)
return; return;
} }
for (size_t i = 0; i < thread_sum; i++)
{
fd_info[i][0] = 65533;
}
if (hos_cache) if (hos_cache)
{ {
hos_cache = (size_t *)realloc(hos_cache, thread_sum * sizeof(size_t)); 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*)); hash_hos_info = (hos_info_t **)calloc(thread_sum, sizeof(hos_info_t*));
} }
if (fd_info) 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])); 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])); 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; client->thread_sum = thread_sum;
return ; return ;
} }