release some memory before exit under Windows

This commit is contained in:
nhmall
2024-11-11 16:50:57 -05:00
parent fd0b67de4d
commit 7414b906b2
4 changed files with 35 additions and 17 deletions

View File

@@ -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();

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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