From 96d39de2231fcd884afd80ce59dec1abc80c23ab Mon Sep 17 00:00:00 2001 From: Sebastian Stal Date: Sun, 15 Sep 2013 10:48:16 -0700 Subject: [PATCH] Fix leaks and null dereferences in net_crypto --- toxcore/net_crypto.c | 10 +++++++--- 1 file 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) return -1; } - if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1) + if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1 + || c->crypto_connections == NULL) return -1; 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, * return -1; * } */ - if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1) + if (realloc_cryptoconnection(c, c->crypto_connections_length + 1) == -1 + || c->crypto_connections == NULL) return -1; memset(&(c->crypto_connections[c->crypto_connections_length]), 0, sizeof(Crypto_Connection)); @@ -778,8 +780,10 @@ Net_Crypto *new_net_crypto(Networking_Core *net) temp->lossless_udp = new_lossless_udp(net); - if (temp->lossless_udp == NULL) + if (temp->lossless_udp == NULL) { + free(temp); return NULL; + } memset(temp->incoming_connections, -1 , sizeof(int) * MAX_INCOMING); return temp;