From be014f9e3c90edd34f3aaa158036b2e96b598bab Mon Sep 17 00:00:00 2001
From: irungentoo <irungentoo@gmail.com>
Date: Wed, 15 Apr 2015 19:52:13 -0400
Subject: [PATCH] Fixed memory leak in TCP connection.

---
 toxcore/TCP_client.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/toxcore/TCP_client.c b/toxcore/TCP_client.c
index eaa248bf..d89b157c 100644
--- a/toxcore/TCP_client.c
+++ b/toxcore/TCP_client.c
@@ -346,6 +346,18 @@ static _Bool add_priority(TCP_Client_Connection *con, const uint8_t *packet, uin
     return 1;
 }
 
+static void wipe_priority_list(TCP_Client_Connection *con)
+{
+    TCP_Priority_List *p = con->priority_queue_start;
+
+    while (p) {
+        TCP_Priority_List *pp = p;
+        p = p->next;
+        free(pp);
+    }
+
+}
+
 /* return 1 on success.
  * return 0 if could not send packet.
  * return -1 on failure (connection must be killed).
@@ -948,6 +960,7 @@ void kill_TCP_connection(TCP_Client_Connection *TCP_connection)
     if (TCP_connection == NULL)
         return;
 
+    wipe_priority_list(TCP_connection);
     kill_sock(TCP_connection->sock);
     memset(TCP_connection, 0, sizeof(TCP_Client_Connection));
     free(TCP_connection);