From 36c5843103c10b7be980589d528ee792e7a83fd7 Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 28 Dec 2023 14:25:39 -0800 Subject: [PATCH] TTY_PERM_INVENT crash fix The change 3 weeks ago for #4059 (to fix tty perm_invent memory leak) resulted in nethack crashing during exit if built with TTY_PERM_INVENT enabled and ending the game when perm_invent window isn't displayed. This exits cleanly with or without perm_invent being shown and avoids the memory leak which triggered the prior change. --- win/tty/wintty.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/win/tty/wintty.c b/win/tty/wintty.c index fb6942ae8..45de400e8 100644 --- a/win/tty/wintty.c +++ b/win/tty/wintty.c @@ -1094,7 +1094,7 @@ tty_clear_nhwindow(winid window) if (cw->active) erase_menu_or_text(window, cw, TRUE); #ifdef TTY_PERM_INVENT - if (window == WIN_INVEN) + if (cw->type == NHW_MENU && cw->mbehavior == MENU_BEHAVE_PERMINV) ttyinv_remove_data(cw, FALSE); else #endif @@ -1989,7 +1989,7 @@ tty_destroy_nhwindow(winid window) if (cw->type == NHW_MAP) term_clear_screen(); #ifdef TTY_PERM_INVENT - if (cw->type == NHW_PERMINVENT || window == WIN_INVEN) + if (cw->type == NHW_MENU && cw->mbehavior == MENU_BEHAVE_PERMINV) ttyinv_remove_data(cw, TRUE); #endif free_window_info(cw, TRUE);