From f23cd539456a29d518593237b36c33fdf9357da2 Mon Sep 17 00:00:00 2001 From: davygrvy Date: Sun, 21 Dec 2003 21:58:43 +0000 Subject: Structured Exception Handling added around Tcl_Finalize called from DllMain's DLL_PROCESS_DETACH. We can't 100% assured that Tcl is being unloaded by the OS in a stable condition and we need to protect the exit handlers should the stack be in a hosed state. AT&T style assembly for SEH under MinGW has not been added yet. This is a first part change for [Patch 858493] --- win/tclWin32Dll.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index dc497f4..b6e1c06 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.c @@ -9,7 +9,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWin32Dll.c,v 1.28 2003/10/13 16:48:07 vincentdarley Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.29 2003/12/21 21:58:43 davygrvy Exp $ */ #include "tclWinInt.h" @@ -232,6 +232,9 @@ DllEntryPoint(hInst, reason, reserved) * * Side effects: * Establishes 32-to-16 bit thunk and initializes sockets library. + * This might call some sycronization functions, but MSDN + * documentation states: "Waiting on synchronization objects in + * DllMain can cause a deadlock." * *---------------------------------------------------------------------- */ @@ -247,8 +250,16 @@ DllMain(hInst, reason, reserved) return TRUE; case DLL_PROCESS_DETACH: - if (hInst == hInstance) { - Tcl_Finalize(); + /* + * Protect the call to Tcl_Finalize. The OS could be unloading + * us from an exception handler and the state of the stack might + * be unstable. + */ + + __try { + Tcl_Finalize(); + } __except (EXCEPTION_EXECUTE_HANDLER) { + /* empty handler body. */ } break; } -- cgit v0.12