tty memory management at program termination

Release some dynamically allocated memory prior to exit.  These were
previously left alone due to assumed complexity (at least by me...),
but dealing with them turned out to be straightforward.

|#if FREE_ALL_MEMORY
 free BASE_WINDOW  -- tty-specific; other windows are drawn on top of it
 free ttyDisplay   -- tty's basic data structure
|#endif
 free nh_HI, nh_HE -- termcap values handled differently from the rest

These are the last things that 'heaputil' always reported as not freed
for the basic Unix+tty configuration.  (I've observed other things not
being freed; those are post-3.4.3 bugs that need to be found and fixed.)
This commit is contained in:
PatR
2015-11-11 01:43:03 -08:00
parent cbeb562d20
commit f97c3dec0a
2 changed files with 61 additions and 40 deletions
+18 -4
View File
@@ -1,4 +1,4 @@
/* NetHack 3.6 wintty.c $NHDT-Date: 1446856765 2015/11/07 00:39:25 $ $NHDT-Branch: master $:$NHDT-Revision: 1.110 $ */
/* NetHack 3.6 wintty.c $NHDT-Date: 1447234979 2015/11/11 09:42:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.112 $ */
/* Copyright (c) David Cohrs, 1991 */
/* NetHack may be freely redistributed. See license for details. */
@@ -1192,14 +1192,28 @@ const char *str;
/* Just forget any windows existed, since we're about to exit anyway.
* Disable windows to avoid calls to window routines.
*/
for (i = 0; i < MAXWIN; i++)
if (wins[i] && (i != BASE_WINDOW)) {
for (i = 0; i < MAXWIN; i++) {
if (i == BASE_WINDOW)
continue; /* handle wins[BASE_WINDOW] last */
if (wins[i]) {
#ifdef FREE_ALL_MEMORY
free_window_info(wins[i], TRUE);
free((genericptr_t) wins[i]);
#endif
wins[i] = 0;
wins[i] = (struct WinDesc *) 0;
}
}
#ifdef FREE_ALL_MEMORY
if (BASE_WINDOW != WIN_ERR && wins[BASE_WINDOW]) {
free_window_info(wins[BASE_WINDOW], TRUE);
free((genericptr_t) wins[BASE_WINDOW]);
wins[BASE_WINDOW] = (struct WinDesc *) 0;
BASE_WINDOW = WIN_ERR;
}
free((genericptr_t) ttyDisplay);
ttyDisplay = (struct DisplayDesc *) 0;
#endif
#ifndef NO_TERMS /*(until this gets added to the window interface)*/
tty_shutdown(); /* cleanup termcap/terminfo/whatever */
#endif