mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed bug in TCP server where memory was expected to be zero but
sometimes wasn't.
This commit is contained in:
parent
3aef4711ce
commit
80e4e5663f
|
@ -73,12 +73,22 @@ static int realloc_connection(TCP_Server *TCP_server, uint32_t num)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (num == TCP_server->size_accepted_connections) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array,
|
TCP_Secure_Connection *new_connections = realloc(TCP_server->accepted_connection_array,
|
||||||
num * sizeof(TCP_Secure_Connection));
|
num * sizeof(TCP_Secure_Connection));
|
||||||
|
|
||||||
if (new_connections == NULL)
|
if (new_connections == NULL)
|
||||||
return -1;
|
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->accepted_connection_array = new_connections;
|
||||||
TCP_server->size_accepted_connections = num;
|
TCP_server->size_accepted_connections = num;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user