diff --git a/sys/windows/consoletty.c b/sys/windows/consoletty.c index be382fdd2..e5f6fa272 100644 --- a/sys/windows/consoletty.c +++ b/sys/windows/consoletty.c @@ -1128,8 +1128,6 @@ consoletty_open(int mode) void consoletty_exit(void) { - /* frees some status tracking data */ - genl_status_finish(); /* go back to using the safe routines */ safe_routines(); free_custom_colors(); diff --git a/sys/windows/windmain.c b/sys/windows/windmain.c index efa09ebb9..d53484edd 100644 --- a/sys/windows/windmain.c +++ b/sys/windows/windmain.c @@ -499,8 +499,9 @@ extern const char *known_restrictions[]; /* symbols.c */ DISABLE_WARNING_UNREACHABLE_CODE -#if defined(__MINGW32__) && defined(MSWIN_GRAPHICS) -#define MAIN mingw_main + +#if defined(MSWIN_GRAPHICS) +#define MAIN nethackw_main #else #define MAIN main #endif diff --git a/sys/windows/windsys.c b/sys/windows/windsys.c index 77d1881bf..7888e4385 100644 --- a/sys/windows/windsys.c +++ b/sys/windows/windsys.c @@ -483,6 +483,10 @@ get_port_id(char *buf) } #endif /* RUNTIME_PORT_ID */ +#ifdef MSWIN_GRAPHICS +extern void free_winmain_stuff(void); +#endif + void nethack_exit(int code) { @@ -506,6 +510,11 @@ nethack_exit(int code) if (iflags.window_inited) wait_synch(); } + /* frees some status tracking data */ + genl_status_finish(); +#ifdef MSWIN_GRAPHICS + free_winmain_stuff(); +#endif exit(code); } diff --git a/win/win32/NetHackW.c b/win/win32/NetHackW.c index 3103f8045..20a5f7591 100644 --- a/win/win32/NetHackW.c +++ b/win/win32/NetHackW.c @@ -82,13 +82,16 @@ static void __cdecl mswin_moveloop(void *); #pragma warning( disable : 28251) #endif +extern int nethackw_main(int argc, char *argv[]); + +static char *argv[MAX_CMDLINE_PARAM]; + int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { INITCOMMONCONTROLSEX InitCtrls; int argc; - char *argv[MAX_CMDLINE_PARAM]; size_t len; TCHAR *p; TCHAR wbuf[BUFSZ]; @@ -210,14 +213,14 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, for (argc = 1; p && argc < MAX_CMDLINE_PARAM; argc++) { len = _tcslen(p); if (len > 0) { - argv[argc] = _strdup(NH_W2A(p, buf, BUFSZ)); + argv[argc] = strdup(NH_W2A(p, buf, BUFSZ)); } else { - argv[argc] = ""; + argv[argc] = strdup(""); } p = _get_cmd_arg(NULL); } GetModuleFileName(NULL, wbuf, BUFSZ); - argv[0] = _strdup(NH_W2A(wbuf, buf, BUFSZ)); + argv[0] = strdup(NH_W2A(wbuf, buf, BUFSZ)); if (argc == 2) { TCHAR *savefile = strdup(argv[1]); @@ -232,8 +235,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, if (*p) { if (strcmp(p + 1, "NetHack-saved-game") == 0) { *p = '\0'; - argv[1] = "-u"; - argv[2] = _strdup(name); + argv[1] = strdup("-u"); + argv[2] = strdup(name); argc = 3; } } @@ -241,16 +244,23 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, free(savefile); } GUILaunched = 1; - /* let main do the argument processing */ -#ifndef __MINGW32__ - main(argc, argv); -#else - int mingw_main(int argc, char *argv[]); - mingw_main(argc, argv); -#endif + /* let nethackw_main do the argument processing */ + nethackw_main(argc, argv); + /* not reached */ return 0; } +void +free_winmain_stuff(void) +{ + int cnt; + + for (cnt = 0; cnt < MAX_CMDLINE_PARAM; ++cnt) { + if (argv[cnt] && argv) + free((genericptr_t) argv[cnt]); + } +} + #ifdef _MSC_VER #pragma warning( pop ) #endif