From 57c22b1acb00b9c4bc70c399a9c099483f76b17d Mon Sep 17 00:00:00 2001 From: irungentoo Date: Fri, 6 Feb 2015 19:10:16 -0500 Subject: [PATCH] Fix memory leaks. --- toxcore/net_crypto.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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) return 0; } +static int clear_buffer(Packets_Array *array) +{ + uint32_t i; + + for (i = array->buffer_start; i != array->buffer_end; ++i) { + uint32_t num = i % CRYPTO_PACKET_BUFFER_SIZE; + + if (array->buffer[num]) { + free(array->buffer[num]); + array->buffer[num] = NULL; + } + } + + array->buffer_start = i; + return 0; +} + /* Set array buffer end to number. * * return -1 on failure. @@ -2705,6 +2722,8 @@ int crypto_kill(Net_Crypto *c, int crypt_connection_id) disconnect_peer_tcp(c, crypt_connection_id); bs_list_remove(&c->ip_port_list, &conn->ip_port, crypt_connection_id); + clear_buffer(&conn->send_array); + clear_buffer(&conn->recv_array); ret = wipe_crypto_connection(c, crypt_connection_id); }