summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-01-31 13:28:22 -0500
committerirungentoo <irungentoo@gmail.com>2015-01-31 13:28:22 -0500
commit33f65929e3f430e9542192d0adf98f1252a911f4 (patch)
treeb4e5edd0dac4ec814c213667b6605fc2af47ff66 /toxcore
parent8e9a971e95fea02e19dd7e187baf38c848515c32 (diff)
Fixed bug where mutex would be destroyed but not recreated for new
net_crypto connection. Only destroy mutex when it is realloced out.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/net_crypto.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index ff6f24ec..3743f1cb 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1378,12 +1378,18 @@ static int wipe_crypto_connection(Net_Crypto *c, int crypt_connection_id)
1378 return -1; 1378 return -1;
1379 1379
1380 uint32_t i; 1380 uint32_t i;
1381 pthread_mutex_destroy(&c->crypto_connections[crypt_connection_id].mutex); 1381
1382 /* Keep mutex, only destroy it when connection is realloced out. */
1383 pthread_mutex_t mutex = c->crypto_connections[crypt_connection_id].mutex;
1382 memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection)); 1384 memset(&(c->crypto_connections[crypt_connection_id]), 0 , sizeof(Crypto_Connection));
1385 c->crypto_connections[crypt_connection_id].mutex = mutex;
1383 1386
1384 for (i = c->crypto_connections_length; i != 0; --i) { 1387 for (i = c->crypto_connections_length; i != 0; --i) {
1385 if (c->crypto_connections[i - 1].status != CRYPTO_CONN_NO_CONNECTION) 1388 if (c->crypto_connections[i - 1].status == CRYPTO_CONN_NO_CONNECTION) {
1389 pthread_mutex_destroy(&c->crypto_connections[i - 1].mutex);
1390 } else {
1386 break; 1391 break;
1392 }
1387 } 1393 }
1388 1394
1389 if (c->crypto_connections_length != i) { 1395 if (c->crypto_connections_length != i) {