summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-09-23 21:00:12 -0400
committerirungentoo <irungentoo@gmail.com>2014-09-23 21:00:12 -0400
commit744f51ec367706e865ca0f6aa70f6bb6e90057d9 (patch)
treeb74364e00a97d753f5dc4dc8f2a5809b9ed413bb
parentda70ef899e0b05774beb81dc2eadbbff4f1ddf66 (diff)
Added some checks to mutex related functions.
-rw-r--r--toxcore/net_crypto.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 0b31d22f..48bf5164 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -1314,10 +1314,12 @@ static int create_crypto_connection(Net_Crypto *c)
1314 int id = -1; 1314 int id = -1;
1315 1315
1316 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == 0) { 1316 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == 0) {
1317 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
1318 id = c->crypto_connections_length; 1317 id = c->crypto_connections_length;
1319 pthread_mutex_init(&c->crypto_connections[id].mutex, NULL);
1320 ++c->crypto_connections_length; 1318 ++c->crypto_connections_length;
1319 memset(&(c->crypto_connections[id]), 0, sizeof(Crypto_Connection));
1320
1321 if (pthread_mutex_init(&c->crypto_connections[id].mutex, NULL) != 0)
1322 return -1;
1321 } 1323 }
1322 1324
1323 pthread_mutex_unlock(&c->connections_mutex); 1325 pthread_mutex_unlock(&c->connections_mutex);
@@ -2642,6 +2644,14 @@ Net_Crypto *new_net_crypto(DHT *dht, TCP_Proxy_Info *proxy_info)
2642 if (temp == NULL) 2644 if (temp == NULL)
2643 return NULL; 2645 return NULL;
2644 2646
2647 pthread_mutexattr_t attr;
2648
2649 if (pthread_mutexattr_init(&attr) != 0 || pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) != 0
2650 || pthread_mutex_init(&temp->tcp_mutex, &attr) != 0 || pthread_mutex_init(&temp->connections_mutex, NULL) != 0) {
2651 free(temp);
2652 return NULL;
2653 }
2654
2645 temp->dht = dht; 2655 temp->dht = dht;
2646 2656
2647 new_keys(temp); 2657 new_keys(temp);
@@ -2656,12 +2666,6 @@ Net_Crypto *new_net_crypto(DHT *dht, TCP_Proxy_Info *proxy_info)
2656 2666
2657 bs_list_init(&temp->ip_port_list, sizeof(IP_Port), 8); 2667 bs_list_init(&temp->ip_port_list, sizeof(IP_Port), 8);
2658 2668
2659 pthread_mutexattr_t attr;
2660 pthread_mutexattr_init(&attr);
2661 pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
2662 pthread_mutex_init(&temp->tcp_mutex, &attr);
2663 pthread_mutex_init(&temp->connections_mutex, NULL);
2664
2665 if (proxy_info) { 2669 if (proxy_info) {
2666 temp->proxy_info = *proxy_info; 2670 temp->proxy_info = *proxy_info;
2667 temp->proxy_set = 1; 2671 temp->proxy_set = 1;