From 8b51448a4c38240f22194f72441bb99ab41f4a7a Mon Sep 17 00:00:00 2001
From: Stefano Miccoli <mocme@icloud.com>
Date: Thu, 28 Aug 2014 12:29:07 +0200
Subject: [PATCH] correcting bug for cleanup routines in ow_net_server.c

"owfree(asd)" MUST be called in child thread (ProcessAcceptSocket)
and NOT in parent routine (ProcessListenSocket)
---
 module/owlib/src/c/ow_net_server.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/module/owlib/src/c/ow_net_server.c b/module/owlib/src/c/ow_net_server.c
index 64484ec..a190694 100644
--- a/module/owlib/src/c/ow_net_server.c
+++ b/module/owlib/src/c/ow_net_server.c
@@ -238,10 +238,10 @@ static void *ProcessAcceptSocket(void *arg)
 
 	// Do the actual work
 	asd->out->HandlerRoutine( asd->acceptfd );
-	// memory freed in calling routine
 
 	// cleanup
 	Test_and_Close( &(asd->acceptfd) );
+	owfree(asd);
 	LEVEL_DEBUG("Normal exit.");
 
 	// All done. If shutdown in progress and this is a last handler thread, send a message to the main thread.
@@ -270,7 +270,8 @@ static void ProcessListenSocket( struct connection_out * out )
 		return ;
 	}
 
-	// allocate space to pass variables to thread -- cleaned up in thread handler
+	// allocate space to pass variables to thread 
+	// MUST be cleaned up in thread handler, not in this routine
 	asd = owmalloc( sizeof(struct Accept_Socket_Data) ) ;
 	if ( asd == NULL ) {
 		LEVEL_DEBUG("Could not allocate memory to handle this request");
@@ -293,7 +294,6 @@ static void ProcessListenSocket( struct connection_out * out )
 			ProcessAcceptSocket(asd) ;
 		}
 	}
-	owfree(asd); // free memory
 
 	RWLOCK_RUNLOCK( shutdown_mutex_rw ) ;
 }
-- 
1.7.10.4

