summaryrefslogtreecommitdiff
path: root/toxcore
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2015-02-06 19:10:16 -0500
committerirungentoo <irungentoo@gmail.com>2015-02-06 19:10:16 -0500
commit57c22b1acb00b9c4bc70c399a9c099483f76b17d (patch)
tree15d733a75b64f8d2bbc42ad1a56c6d9375c7db6b /toxcore
parent01b4ad7a8a6e872d6f43e3922742d34511f60135 (diff)
Fix memory leaks.
Diffstat (limited to 'toxcore')
-rw-r--r--toxcore/net_crypto.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c
index 3743f1cb..1925d95f 100644
--- a/toxcore/net_crypto.c
+++ b/toxcore/net_crypto.c
@@ -608,6 +608,23 @@ static int clear_buffer_until(Packets_Array *array, uint32_t number)
608 return 0; 608 return 0;
609} 609}
610 610
611static int clear_buffer(Packets_Array *array)
612{
613 uint32_t i;
614
615 for (i = array->buffer_start; i != array->buffer_end; ++i) {
616 uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE;
617
618 if (array->buffer[num]) {
619 free(array->buffer[num]);
620 array->buffer[num] = NULL;
621 }
622 }
623
624 array->buffer_start = i;
625 return 0;
626}
627
611/* Set array buffer end to number. 628/* Set array buffer end to number.
612 * 629 *
613 * return -1 on failure. 630 * return -1 on failure.
@@ -2705,6 +2722,8 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id)
2705 2722
2706 disconnect_peer_tcp(c, crypt_connection_id); 2723 disconnect_peer_tcp(c, crypt_connection_id);
2707 bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); 2724 bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id);
2725 clear_buffer(&conn->send_array);
2726 clear_buffer(&conn->recv_array);
2708 ret = wipe_crypto_connection(c, crypt_connection_id); 2727 ret = wipe_crypto_connection(c, crypt_connection_id);
2709 } 2728 }
2710 2729