Windows: free more allocated memory before exit
This gets rid of the final leak complaint on Windows as of Nov 13, 2024
This commit is contained in:
@@ -131,7 +131,7 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
||||
windowprocs.win_wait_synch = mswin_wait_synch;
|
||||
|
||||
win10_init();
|
||||
early_init(0, NULL); /* Change as needed to support CRASHREPORT */
|
||||
/* early_init(0, NULL); */ /* Change as needed to support CRASHREPORT */
|
||||
|
||||
/* init application structure */
|
||||
_nethack_app.hApp = hInstance;
|
||||
@@ -166,6 +166,8 @@ WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine,
|
||||
|
||||
_nethack_app.bNoHScroll = FALSE;
|
||||
_nethack_app.bNoVScroll = FALSE;
|
||||
if (_nethack_app.saved_text)
|
||||
free(_nethack_app.saved_text), _nethack_app.saved_text = 0;
|
||||
_nethack_app.saved_text = strdup("");
|
||||
|
||||
_nethack_app.bAutoLayout = TRUE;
|
||||
@@ -257,7 +259,17 @@ free_winmain_stuff(void)
|
||||
|
||||
for (cnt = 0; cnt < MAX_CMDLINE_PARAM; ++cnt) {
|
||||
if (argv[cnt])
|
||||
free((genericptr_t) argv[cnt]);
|
||||
free((genericptr_t) argv[cnt]), argv[cnt] = 0;
|
||||
}
|
||||
if (_nethack_app.saved_text)
|
||||
free((genericptr_t) _nethack_app.saved_text),
|
||||
_nethack_app.saved_text = 0;
|
||||
for (cnt = 0; cnt < MAXWINDOWS; ++cnt) {
|
||||
if (windowdata[cnt].address) {
|
||||
if (!windowdata[cnt].isstatic)
|
||||
free(windowdata[cnt].address);
|
||||
windowdata[cnt].address = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -208,9 +208,11 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
data = (PNHMainWindow) malloc(sizeof(NHMainWindow));
|
||||
if (!data)
|
||||
panic("out of memory");
|
||||
|
||||
ZeroMemory(data, sizeof(NHMainWindow));
|
||||
data->mapAcsiiModeSave = MAP_MODE_ASCII12x16;
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
|
||||
windowdata[NHW_MAIN].address = (genericptr_t) data;
|
||||
|
||||
/* update menu items */
|
||||
CheckMenuItem(
|
||||
@@ -509,7 +511,7 @@ MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
/* clean up */
|
||||
free((PNHMainWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA));
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
|
||||
windowdata[NHW_MAIN].address = 0;
|
||||
// PostQuitMessage(0);
|
||||
exit(1);
|
||||
break;
|
||||
|
||||
@@ -641,6 +641,7 @@ MapWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
DeleteDC(data->backBufferDC);
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_MAP].address = 0;
|
||||
break;
|
||||
|
||||
case WM_TIMER:
|
||||
@@ -834,6 +835,7 @@ onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
ReleaseDC(hWnd, hDC);
|
||||
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
|
||||
windowdata[NHW_MAP].address = (genericptr_t) data;
|
||||
|
||||
clearAll(data);
|
||||
|
||||
|
||||
@@ -298,6 +298,7 @@ MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
data->bmpDC = CreateCompatibleDC(hdc);
|
||||
data->is_active = FALSE;
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
|
||||
windowdata[NHW_MENU].address = (genericptr_t) data;
|
||||
}
|
||||
/* set font for the text control */
|
||||
cached_font * font = mswin_get_font(NHW_MENU, ATR_NONE, hdc, FALSE);
|
||||
@@ -519,6 +520,7 @@ MenuWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
}
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_MENU].address = 0;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -171,6 +171,7 @@ NHMessageWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
data = (PNHMessageWindow) GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_MESSAGE].address = 0;
|
||||
} break;
|
||||
|
||||
case WM_SIZE: {
|
||||
@@ -729,6 +730,7 @@ onCreate(HWND hWnd, WPARAM wParam, LPARAM lParam)
|
||||
ZeroMemory(data, sizeof(NHMessageWindow));
|
||||
data->max_text = MAXWINDOWTEXT;
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) data);
|
||||
windowdata[NHW_MESSAGE].address = (genericptr_t) data; // for cleanup at the end
|
||||
|
||||
/* re-calculate window size (+ font size) */
|
||||
mswin_message_window_size(hWnd, &dummy);
|
||||
|
||||
@@ -56,6 +56,7 @@ mswin_init_RIP_window(void)
|
||||
|
||||
ZeroMemory(data, sizeof(NHRIPWindow));
|
||||
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
|
||||
windowdata[NHW_RIP].address = (genericptr_t) data;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -240,6 +241,7 @@ NHRIPWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
DeleteObject(data->rip_bmp);
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_RIP].address = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,8 @@ mswin_display_splash_window(BOOL show_ver)
|
||||
mswin_set_splash_data(hWnd, &splashData, monitorInfo.scale);
|
||||
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) &splashData);
|
||||
windowdata[NHW_SPLASH].address = (genericptr_t) &splashData;
|
||||
windowdata[NHW_SPLASH].isstatic = 1;
|
||||
|
||||
GetNHApp()->hPopupWnd = hWnd;
|
||||
|
||||
|
||||
@@ -127,6 +127,7 @@ mswin_init_status_window(void)
|
||||
if (!data)
|
||||
panic("out of memory");
|
||||
|
||||
windowdata[NHW_STATUS].address = (genericptr_t) data;
|
||||
ZeroMemory(data, sizeof(NHStatusWindow));
|
||||
SetWindowLongPtr(ret, GWLP_USERDATA, (LONG_PTR) data);
|
||||
|
||||
@@ -253,6 +254,7 @@ StatusWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
case WM_DESTROY:
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_STATUS].address = 0;
|
||||
break;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
|
||||
@@ -83,8 +83,10 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
data = (PNHTextWindow)malloc(sizeof(NHTextWindow));
|
||||
if (!data)
|
||||
panic("out of memory");
|
||||
|
||||
ZeroMemory(data, sizeof(NHTextWindow));
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)data);
|
||||
windowdata[NHW_TEXT].address = (genericptr_t) data; // for cleanup at the end
|
||||
|
||||
HWND control = GetDlgItem(hWnd, IDC_TEXT_CONTROL);
|
||||
HDC hdc = GetDC(control);
|
||||
@@ -173,6 +175,7 @@ NHTextWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
free(data->window_text);
|
||||
free(data);
|
||||
SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR) 0);
|
||||
windowdata[NHW_TEXT].address = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1021,6 +1021,7 @@ mswin_putstr_ex(winid wid, int attr, const char *text, int app)
|
||||
|
||||
if (GetNHApp()->windowlist[wid].win != NULL) {
|
||||
MSNHMsgPutstr data;
|
||||
|
||||
ZeroMemory(&data, sizeof(data));
|
||||
data.attr = attr;
|
||||
data.text = text;
|
||||
@@ -2110,30 +2111,32 @@ mswin_preference_update(const char *pref)
|
||||
}
|
||||
}
|
||||
|
||||
static PMSNHMsgGetText history_text = 0;
|
||||
static char *next_message = 0;
|
||||
|
||||
char *
|
||||
mswin_getmsghistory(boolean init)
|
||||
{
|
||||
static PMSNHMsgGetText text = 0;
|
||||
static char *next_message = 0;
|
||||
|
||||
if (init) {
|
||||
text = (PMSNHMsgGetText) malloc(sizeof(MSNHMsgGetText)
|
||||
if (history_text)
|
||||
free((genericptr_t) history_text), history_text = 0;
|
||||
history_text = (PMSNHMsgGetText) malloc(sizeof(MSNHMsgGetText)
|
||||
+ TEXT_BUFFER_SIZE);
|
||||
if (text) {
|
||||
text->max_size =
|
||||
if (history_text) {
|
||||
history_text->max_size =
|
||||
TEXT_BUFFER_SIZE
|
||||
- 1; /* make sure we always have 0 at the end of the buffer */
|
||||
|
||||
ZeroMemory(text->buffer, TEXT_BUFFER_SIZE);
|
||||
ZeroMemory(history_text->buffer, TEXT_BUFFER_SIZE);
|
||||
SendMessage(mswin_hwnd_from_winid(WIN_MESSAGE), WM_MSNH_COMMAND,
|
||||
(WPARAM) MSNH_MSG_GETTEXT, (LPARAM) text);
|
||||
(WPARAM) MSNH_MSG_GETTEXT, (LPARAM) history_text);
|
||||
|
||||
next_message = text->buffer;
|
||||
next_message = history_text->buffer;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(next_message && next_message[0])) {
|
||||
free(text);
|
||||
free(history_text), history_text = 0;
|
||||
next_message = 0;
|
||||
return (char *) 0;
|
||||
} else {
|
||||
|
||||
@@ -43,8 +43,18 @@
|
||||
#define MAXWINDOWS 15
|
||||
#endif
|
||||
|
||||
#define NHW_RIP 32
|
||||
#define NHW_INVEN 33
|
||||
struct window_tracking_data {
|
||||
genericptr_t address;
|
||||
int isstatic;
|
||||
} windowdata[MAXWINDOWS];
|
||||
|
||||
/* these are only in MSWIN_GRAPHICS, not the core */
|
||||
enum mswin_window_types {
|
||||
NHW_MAIN = (NHW_LAST_TYPE + 1),
|
||||
NHW_INVEN,
|
||||
NHW_RIP,
|
||||
NHW_SPLASH
|
||||
};
|
||||
|
||||
#ifndef TILE_X
|
||||
#define TILE_X 16
|
||||
|
||||
Reference in New Issue
Block a user