diff options
-rw-r--r-- | toxcore/TCP_server.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/toxcore/TCP_server.c b/toxcore/TCP_server.c index 31884604..ceab5f10 100644 --- a/toxcore/TCP_server.c +++ b/toxcore/TCP_server.c | |||
@@ -73,12 +73,22 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num) | |||
73 | return 0; | 73 | return 0; |
74 | } | 74 | } |
75 | 75 | ||
76 | if (num == TCP_server->size_accepted_connections) { | ||
77 | return 0; | ||
78 | } | ||
79 | |||
76 | TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array, | 80 | TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array, |
77 | num * sizeof(TCP_Secure_Connection)); | 81 | num * sizeof(TCP_Secure_Connection)); |
78 | 82 | ||
79 | if (new_connections == NULL) | 83 | if (new_connections == NULL) |
80 | return -1; | 84 | return -1; |
81 | 85 | ||
86 | if (num > TCP_server->size_accepted_connections) { | ||
87 | uint32_t old_size = TCP_server->size_accepted_connections; | ||
88 | uint32_t size_new_entries = (num - old_size) * sizeof(TCP_Secure_Connection); | ||
89 | memset(new_connections + old_size, 0, size_new_entries); | ||
90 | } | ||
91 | |||
82 | TCP_server->accepted_connection_array = new_connections; | 92 | TCP_server->accepted_connection_array = new_connections; |
83 | TCP_server->size_accepted_connections = num; | 93 | TCP_server->size_accepted_connections = num; |
84 | return 0; | 94 | return 0; |