Skip to content

Commit

Permalink
Fixed bug in TCP server where memory was expected to be zero but
Browse files Browse the repository at this point in the history
sometimes wasn't.
  • Loading branch information
irungentoo committed May 17, 2014
1 parent 3aef471 commit 80e4e56
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions toxcore/TCP_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 80e4e56

Please sign in to comment.