From 84976ed5dc001050613667c172709e82f124f36d Mon Sep 17 00:00:00 2001
From: Campus <campus@ntop.org>
Date: Tue, 16 Feb 2016 12:23:56 +0100
Subject: fix for https://github.com/ntop/nDPI/issues/148

---
 example/ndpiReader.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

(limited to 'example/ndpiReader.c')

diff --git a/example/ndpiReader.c b/example/ndpiReader.c
index 4d1ae1296..bb6ee81c8 100644
--- a/example/ndpiReader.c
+++ b/example/ndpiReader.c
@@ -1104,10 +1104,15 @@ static unsigned int packet_processing(u_int16_t thread_id,
       ndpi_twalk(ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_idle_scan_walker, &thread_id);
 
       /* remove idle flows (unfortunately we cannot do this inline) */
-      while (ndpi_thread_info[thread_id].num_idle_flows > 0)
-	ndpi_tdelete(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows],
-		     &ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_cmp);
-
+      while (ndpi_thread_info[thread_id].num_idle_flows > 0) {
+	
+	/* search and delete the idle flow from the "ndpi_flow_root" (see struct reader thread) - here flows are the node of a b-tree */
+	ndpi_tdelete(ndpi_thread_info[thread_id].idle_flows[--ndpi_thread_info[thread_id].num_idle_flows], &ndpi_thread_info[thread_id].ndpi_flows_root[ndpi_thread_info[thread_id].idle_scan_idx], node_cmp);
+	
+	/* free the memory associated to idle flow in "idle_flows" - (see struct reader thread)*/
+	free_ndpi_flow(ndpi_thread_info[thread_id].idle_flows[ndpi_thread_info[thread_id].num_idle_flows]);
+      }
+      
       if(++ndpi_thread_info[thread_id].idle_scan_idx == NUM_ROOTS) ndpi_thread_info[thread_id].idle_scan_idx = 0;
       ndpi_thread_info[thread_id].last_idle_scan_time = ndpi_thread_info[thread_id].last_time;
     }
-- 
cgit v1.2.3