From 80e4e5663fac23c4f57f58264caff6aa04a27713 Mon Sep 17 00:00:00 2001 From: irungentoo Date: Sat, 17 May 2014 14:29:28 -0400 Subject: Fixed bug in TCP server where memory was expected to be zero but sometimes wasn't. --- toxcore/TCP_server.c | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) return 0; } + if (num == TCP_server->size_accepted_connections) { + return 0; + } + TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array, num * sizeof(TCP_Secure_Connection)); if (new_connections == NULL) return -1; + if (num > TCP_server->size_accepted_connections) { + uint32_t old_size = TCP_server->size_accepted_connections; + uint32_t size_new_entries = (num - old_size) * sizeof(TCP_Secure_Connection); + memset(new_connections + old_size, 0, size_new_entries); + } + TCP_server->accepted_connection_array = new_connections; TCP_server->size_accepted_connections = num; return 0; -- cgit v1.2.3