Fixed bug in TCP server where memory was expected to be zero but

sometimes wasn't.
This commit is contained in:
irungentoo 2014-05-17 14:29:28 -04:00
parent 3aef4711ce
commit 80e4e5663f
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -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;