Subject: Free the WinThread structure before running the original thread procedure.

From: Joe Mistachkin <[email-masked]>
Date: Thu, 13 Sep 2012 18:37:55 +0000

---
 win/tclWinThrd.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/win/tclWinThrd.c b/win/tclWinThrd.c
index 7abcc29..86ff6a5 100644
--- a/win/tclWinThrd.c
+++ b/win/tclWinThrd.c
@@ -161,13 +161,20 @@ TclWinThreadStart(
 {
     WinThread *winThreadPtr = (WinThread *) lpParameter;
     unsigned int fpmask = _MCW_EM | _MCW_RC | _MCW_PC | _MCW_DN;
+    LPTHREAD_START_ROUTINE lpOrigStartAddress;
+    LPVOID lpOrigParameter;
 
     if (!winThreadPtr) {
 	return TCL_ERROR;
     }
 
     _controlfp(winThreadPtr->fpControl, fpmask);
-    return winThreadPtr->lpStartAddress(winThreadPtr->lpParameter);
+
+    lpOrigStartAddress = winThreadPtr->lpStartAddress;
+    lpOrigParameter = winThreadPtr->lpParameter;
+
+    ckfree((char *)winThreadPtr);
+    return lpOrigStartAddress(lpOrigParameter);
 }
 
 /*
-- 
cgit v0.12