summaryrefslogtreecommitdiffstats
path: root/win/winMain.c
diff options
context:
space:
mode:
authorpatthoyts@users.sourceforge.net <patthoyts>2003-10-14 15:35:50 (GMT)
committerpatthoyts@users.sourceforge.net <patthoyts>2003-10-14 15:35:50 (GMT)
commit379969b62b4e43166542467d2adea0c98b4a5115 (patch)
tree63c637aacb46feeb4a00e2d25944ade18e6b33d3 /win/winMain.c
parent29e14de50e0e780a60d52f15cc618f015a361aff (diff)
downloadtk-379969b62b4e43166542467d2adea0c98b4a5115.zip
tk-379969b62b4e43166542467d2adea0c98b4a5115.tar.gz
tk-379969b62b4e43166542467d2adea0c98b4a5115.tar.bz2
* win/makefile.vc: Applied patches from tcl bug #801467 from
* win/winMain.c: Joe Mistachkin
Diffstat (limited to 'win/winMain.c')
-rw-r--r--win/winMain.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/win/winMain.c b/win/winMain.c
index edfd42f..83fe80e 100644
--- a/win/winMain.c
+++ b/win/winMain.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: winMain.c,v 1.15 2002/11/04 07:49:43 davygrvy Exp $
+ * RCS: @(#) $Id: winMain.c,v 1.16 2003/10/14 15:35:52 patthoyts Exp $
*/
#include <tk.h>
@@ -33,12 +33,14 @@
static void setargv _ANSI_ARGS_((int *argcPtr, char ***argvPtr));
static void WishPanic _ANSI_ARGS_(TCL_VARARGS(CONST char *,format));
+static void AppInitExitHandler(ClientData clientData);
#ifdef TK_TEST
extern int Tktest_Init(Tcl_Interp *interp);
#endif /* TK_TEST */
static BOOL consoleRequired = TRUE;
+static char **argvSave = NULL;
/*
* The following #if block allows you to change the AppInit
@@ -111,6 +113,11 @@ WinMain(hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
setargv(&argc, &argv);
/*
+ * Save this for later, so we can free it.
+ */
+ argvSave = argv;
+
+ /*
* Replace argv[0] with full pathname of executable, and forward
* slashes substituted for backslashes.
*/
@@ -164,6 +171,12 @@ Tcl_AppInit(interp)
Tcl_StaticPackage(interp, "Tk", Tk_Init, Tk_SafeInit);
/*
+ * This exit handler will be used to free the
+ * resources allocated in this file.
+ */
+ Tcl_CreateExitHandler(AppInitExitHandler, NULL);
+
+ /*
* Initialize the console only if we are running as an interactive
* application.
*/
@@ -244,6 +257,34 @@ WishPanic TCL_VARARGS_DEF(CONST char *,arg1)
#endif
ExitProcess(1);
}
+
+/*
+ *----------------------------------------------------------------------
+ *
+ * AppInitExitHandler --
+ *
+ * This function is called to cleanup the app init resources before
+ * Tcl is unloaded.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Frees the saved argv and deletes the async exit handler.
+ *
+ *----------------------------------------------------------------------
+ */
+
+static void
+AppInitExitHandler(
+ ClientData clientData)
+{
+ if (argvSave != NULL) {
+ ckfree((char *)argvSave);
+ argvSave = NULL;
+ }
+}
+
/*
*-------------------------------------------------------------------------
*
@@ -299,7 +340,7 @@ setargv(argcPtr, argvPtr)
}
}
}
- argSpace = (char *) Tcl_Alloc(
+ argSpace = (char *) ckalloc(
(unsigned) (size * sizeof(char *) + strlen(cmdLine) + 1));
argv = (char **) argSpace;
argSpace += size * sizeof(char *);