summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-05-17 14:29:28 -0400
committerirungentoo <irungentoo@gmail.com>2014-05-17 14:29:28 -0400
commit80e4e5663fac23c4f57f58264caff6aa04a27713 (patch)
tree7e7f51b107d78c72524e32ad1a845e3cce75840a
parent3aef4711ce4587fe3e48e505eff61373100fd335 (diff)
Fixed bug in TCP server where memory was expected to be zero but
sometimes wasn't.
-rw-r--r--toxcore/TCP_server.c10
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;