Index: src/main.c ================================================================== --- src/main.c +++ src/main.c @@ -346,20 +346,20 @@ /* ** atexit() handler which frees up "some" of the resources ** used by fossil. */ static void fossil_atexit(void) { -#if defined(_WIN32) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) +#if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) /* ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash ** when exiting while a stubs-enabled Tcl is still loaded. This is due to ** a bug in MinGW, see: ** ** http://comments.gmane.org/gmane.comp.gnu.mingw.user/41724 ** ** The workaround is to manually unload the loaded Tcl library prior to - ** exiting the process. + ** exiting the process. Win64 is not affected. */ unloadTcl(g.interp, &g.tcl); #endif #ifdef FOSSIL_ENABLE_JSON cson_value_free(g.json.gc.v); Index: src/th_tcl.c ================================================================== --- src/th_tcl.c +++ src/th_tcl.c @@ -868,49 +868,35 @@ return TH_ERROR; } return TH_OK; } +#if defined(_WIN32) && !defined(_WIN64) && defined(FOSSIL_ENABLE_TCL) && defined(USE_TCL_STUBS) /* ** Finalizes and unloads the previously loaded Tcl library, if applicable. */ int unloadTcl( Th_Interp *interp, void *pContext ){ struct TclContext *tclContext = (struct TclContext *)pContext; Tcl_Interp *tclInterp; - tcl_FinalizeProc *xFinalize; -#if defined(USE_TCL_STUBS) void *library; -#endif /* defined(USE_TCL_STUBS) */ if ( !tclContext ){ Th_ErrorMessage(interp, "invalid Tcl context", (const char *)"", 0); return TH_ERROR; } /* - ** Grab the Tcl_Finalize function pointer prior to deleting the Tcl - ** interpreter because the memory backing the Tcl stubs table will - ** be going away. - */ - xFinalize = tclContext->xFinalize; - /* ** If the Tcl interpreter has been created, formally delete it now. */ tclInterp = tclContext->interp; if ( tclInterp ){ Tcl_DeleteInterp(tclInterp); - tclContext->interp = tclInterp = 0; - } - /* - ** If the Tcl library is not finalized prior to unloading it, a deadlock - ** can occur in some circumstances (i.e. the [clock] thread is running). - */ - if( xFinalize ) xFinalize(); -#if defined(USE_TCL_STUBS) + tclContext->interp = 0; + } /* ** If Tcl is compiled on Windows using the latest MinGW, Fossil can crash ** when exiting while a stubs-enabled Tcl is still loaded. This is due to ** a bug in MinGW, see: ** @@ -919,16 +905,21 @@ ** The workaround is to manually unload the loaded Tcl library prior to ** exiting the process. */ library = tclContext->library; if( library ){ + /* + ** If the Tcl library is not finalized prior to unloading it, a deadlock + ** can occur in some circumstances (i.e. the [clock] thread is running). + */ + tclContext->xFinalize(); dlclose(library); - tclContext->library = library = 0; + tclContext->library = 0; } -#endif /* defined(USE_TCL_STUBS) */ return TH_OK; } +#endif /* ** Register the Tcl language commands with interpreter interp. ** Usually this is called soon after interpreter creation. */