summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Stal <stal@kirara.ca>2013-09-15 10:48:16 -0700
committerSebastian Stal <stal@kirara.ca>2013-09-15 10:48:16 -0700
commit96d39de2231fcd884afd80ce59dec1abc80c23ab (patch)
treee10b6149a3df0b4cba727af0ec9aa3f09865d243
parentdecdb7aa8c827787240bac66526a81bf2b8f7ebb (diff)
Fix leaks and null dereferences in net_crypto
-rw-r--r--toxcore/net_crypto.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 3f866f74..1de32cb0 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -455,7 +455,8 @@ int crypto_connect(Net_Crypto *c, uint8_t *public_key, IP_Port ip_port)
455 return -1; 455 return -1;
456 } 456 }
457 457
458 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1) 458 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1
459 || c->crypto_connections == NULL)
459 return -1; 460 return -1;
460 461
461 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); 462 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
@@ -578,7 +579,8 @@ int accept_crypto_inbound(Net_Crypto *c, int connection_id, uint8_t *public_key,
578 * return -1; 579 * return -1;
579 * } 580 * }
580 */ 581 */
581 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1) 582 if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1
583 || c->crypto_connections == NULL)
582 return -1; 584 return -1;
583 585
584 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); 586 memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection));
@@ -778,8 +780,10 @@ Net_Crypto *new_net_crypto(Networking_Core *net)
778 780
779 temp->lossless_udp = new_lossless_udp(net); 781 temp->lossless_udp = new_lossless_udp(net);
780 782
781 if (temp->lossless_udp == NULL) 783 if (temp->lossless_udp == NULL) {
784 free(temp);
782 return NULL; 785 return NULL;
786 }
783 787
784 memset(temp->incoming_connections, -1 , sizeof(int) * MAX_INCOMING); 788 memset(temp->incoming_connections, -1 , sizeof(int) * MAX_INCOMING);
785 return temp; 789 return temp;