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:
+43
-36
@@ -1,4 +1,4 @@
|
|||||||
/* NetHack 3.6 termcap.c $NHDT-Date: 1446856761 2015/11/07 00:39:21 $ $NHDT-Branch: master $:$NHDT-Revision: 1.22 $ */
|
/* NetHack 3.6 termcap.c $NHDT-Date: 1447234979 2015/11/11 09:42:59 $ $NHDT-Branch: master $:$NHDT-Revision: 1.23 $ */
|
||||||
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
/* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* NetHack may be freely redistributed. See license for details. */
|
||||||
|
|
||||||
@@ -30,8 +30,7 @@ static void NDECL(init_hilite);
|
|||||||
static void NDECL(kill_hilite);
|
static void NDECL(kill_hilite);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE,
|
/* (see tcap.h) -- nh_CM, nh_ND, nh_CD, nh_HI,nh_HE, nh_US,nh_UE, ul_hack */
|
||||||
ul_hack */
|
|
||||||
struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE };
|
struct tc_lcl_data tc_lcl_data = { 0, 0, 0, 0, 0, 0, 0, FALSE };
|
||||||
|
|
||||||
STATIC_VAR char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE;
|
STATIC_VAR char *HO, *CL, *CE, *UP, *XD, *BC, *SO, *SE, *TI, *TE;
|
||||||
@@ -44,6 +43,7 @@ STATIC_VAR char *MD; /* may already be in use below */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef TERMLIB
|
#ifdef TERMLIB
|
||||||
|
boolean dynamic_HIHE = FALSE;
|
||||||
#ifdef TEXTCOLOR
|
#ifdef TEXTCOLOR
|
||||||
STATIC_VAR char *MD;
|
STATIC_VAR char *MD;
|
||||||
#endif
|
#endif
|
||||||
@@ -152,9 +152,9 @@ int *wid, *hgt;
|
|||||||
nh_US = "\033[4m";
|
nh_US = "\033[4m";
|
||||||
MR = "\033[7m";
|
MR = "\033[7m";
|
||||||
TI = nh_HE = ME = SE = nh_UE = "\033[0m";
|
TI = nh_HE = ME = SE = nh_UE = "\033[0m";
|
||||||
/* strictly, SE should be 2, and nh_UE should be 24,
|
/* strictly, SE should be 2, and nh_UE should be 24,
|
||||||
but we can't trust all ANSI emulators to be
|
but we can't trust all ANSI emulators to be
|
||||||
that complete. -3. */
|
that complete. -3. */
|
||||||
#ifndef MICRO
|
#ifndef MICRO
|
||||||
AS = "\016";
|
AS = "\016";
|
||||||
AE = "\017";
|
AE = "\017";
|
||||||
@@ -221,11 +221,11 @@ int *wid, *hgt;
|
|||||||
#else
|
#else
|
||||||
HO = Tgetstr("ho");
|
HO = Tgetstr("ho");
|
||||||
#endif
|
#endif
|
||||||
/*
|
/*
|
||||||
* LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If
|
* LI and CO are set in ioctl.c via a TIOCGWINSZ if available. If
|
||||||
* the kernel has values for either we should use them rather than
|
* the kernel has values for either we should use them rather than
|
||||||
* the values from TERMCAP ...
|
* the values from TERMCAP ...
|
||||||
*/
|
*/
|
||||||
#ifndef MICRO
|
#ifndef MICRO
|
||||||
if (!CO)
|
if (!CO)
|
||||||
CO = tgetnum("co");
|
CO = tgetnum("co");
|
||||||
@@ -233,18 +233,17 @@ int *wid, *hgt;
|
|||||||
LI = tgetnum("li");
|
LI = tgetnum("li");
|
||||||
#else
|
#else
|
||||||
#if defined(TOS) && defined(__GNUC__)
|
#if defined(TOS) && defined(__GNUC__)
|
||||||
if (!strcmp(term, "builtin"))
|
if (!strcmp(term, "builtin")) {
|
||||||
get_scr_size();
|
get_scr_size();
|
||||||
else {
|
} else
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
CO = tgetnum("co");
|
CO = tgetnum("co");
|
||||||
LI = tgetnum("li");
|
LI = tgetnum("li");
|
||||||
if (!LI || !CO) /* if we don't override it */
|
if (!LI || !CO) /* if we don't override it */
|
||||||
get_scr_size();
|
get_scr_size();
|
||||||
#if defined(TOS) && defined(__GNUC__)
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* ?MICRO */
|
||||||
#endif
|
|
||||||
#ifdef CLIPPING
|
#ifdef CLIPPING
|
||||||
if (CO < COLNO || LI < ROWNO + 3)
|
if (CO < COLNO || LI < ROWNO + 3)
|
||||||
setclipped();
|
setclipped();
|
||||||
@@ -298,16 +297,14 @@ int *wid, *hgt;
|
|||||||
* pager as a string - so how can you send it NULs???
|
* pager as a string - so how can you send it NULs???
|
||||||
* -jsb
|
* -jsb
|
||||||
*/
|
*/
|
||||||
nh_HI = (char *) alloc((unsigned) (strlen(SO) + 1));
|
for (i = 0; digit(SO[i]); ++i)
|
||||||
nh_HE = (char *) alloc((unsigned) (strlen(ME) + 1));
|
continue;
|
||||||
i = 0;
|
nh_HI = dupstr(&SO[i]);
|
||||||
while (digit(SO[i]))
|
for (i = 0; digit(ME[i]); ++i)
|
||||||
i++;
|
continue;
|
||||||
Strcpy(nh_HI, &SO[i]);
|
nh_HE = dupstr(&ME[i]);
|
||||||
i = 0;
|
dynamic_HIHE = TRUE;
|
||||||
while (digit(ME[i]))
|
|
||||||
i++;
|
|
||||||
Strcpy(nh_HE, &ME[i]);
|
|
||||||
AS = Tgetstr("as");
|
AS = Tgetstr("as");
|
||||||
AE = Tgetstr("ae");
|
AE = Tgetstr("ae");
|
||||||
nh_CD = Tgetstr("cd");
|
nh_CD = Tgetstr("cd");
|
||||||
@@ -340,10 +337,17 @@ int *wid, *hgt;
|
|||||||
void
|
void
|
||||||
tty_shutdown()
|
tty_shutdown()
|
||||||
{
|
{
|
||||||
#if defined(TEXTCOLOR) && defined(TERMLIB)
|
/* we only attempt to clean up a few individual termcap variables */
|
||||||
|
#ifdef TERMLIB
|
||||||
|
#ifdef TEXTCOLOR
|
||||||
kill_hilite();
|
kill_hilite();
|
||||||
#endif
|
#endif
|
||||||
/* we don't attempt to clean up individual termcap variables [yet?] */
|
if (dynamic_HIHE) {
|
||||||
|
free((genericptr_t) nh_HI), nh_HI = (char *) 0;
|
||||||
|
free((genericptr_t) nh_HE), nh_HE = (char *) 0;
|
||||||
|
dynamic_HIHE = FALSE;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -570,7 +574,8 @@ register int x, y;
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* See note above. xputc() is a special function. */
|
/* See note above. xputc() is a special function. */
|
||||||
void xputc(c)
|
void
|
||||||
|
xputc(c)
|
||||||
#if defined(apollo)
|
#if defined(apollo)
|
||||||
int c;
|
int c;
|
||||||
#else
|
#else
|
||||||
@@ -758,7 +763,7 @@ tty_delay_output()
|
|||||||
#else /* MICRO */
|
#else /* MICRO */
|
||||||
/* BUG: if the padding character is visible, as it is on the 5620
|
/* BUG: if the padding character is visible, as it is on the 5620
|
||||||
then this looks terrible. */
|
then this looks terrible. */
|
||||||
if (flags.null)
|
if (flags.null) {
|
||||||
#ifdef TERMINFO
|
#ifdef TERMINFO
|
||||||
/* cbosgd!cbcephus!pds for SYS V R2 */
|
/* cbosgd!cbcephus!pds for SYS V R2 */
|
||||||
#ifdef NHSTDC
|
#ifdef NHSTDC
|
||||||
@@ -774,7 +779,7 @@ tty_delay_output()
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
else if (ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) {
|
} else if (ospeed > 0 && ospeed < SIZE(tmspc10) && nh_CM) {
|
||||||
/* delay by sending cm(here) an appropriate number of times */
|
/* delay by sending cm(here) an appropriate number of times */
|
||||||
register int cmlen =
|
register int cmlen =
|
||||||
strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury));
|
strlen(tgoto(nh_CM, ttyDisplay->curx, ttyDisplay->cury));
|
||||||
@@ -788,13 +793,15 @@ tty_delay_output()
|
|||||||
#endif /* MICRO */
|
#endif /* MICRO */
|
||||||
}
|
}
|
||||||
|
|
||||||
void cl_eos() /* free after Robert Viduya */
|
/* must only be called with curx = 1 */
|
||||||
{ /* must only be called with curx = 1 */
|
void
|
||||||
|
cl_eos() /* free after Robert Viduya */
|
||||||
if (nh_CD)
|
{
|
||||||
|
if (nh_CD) {
|
||||||
xputs(nh_CD);
|
xputs(nh_CD);
|
||||||
else {
|
} else {
|
||||||
register int cy = ttyDisplay->cury + 1;
|
register int cy = ttyDisplay->cury + 1;
|
||||||
|
|
||||||
while (cy <= LI - 2) {
|
while (cy <= LI - 2) {
|
||||||
cl_end();
|
cl_end();
|
||||||
xputc('\n');
|
xputc('\n');
|
||||||
|
|||||||
+18
-4
@@ -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 */
|
/* Copyright (c) David Cohrs, 1991 */
|
||||||
/* NetHack may be freely redistributed. See license for details. */
|
/* 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.
|
/* Just forget any windows existed, since we're about to exit anyway.
|
||||||
* Disable windows to avoid calls to window routines.
|
* Disable windows to avoid calls to window routines.
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < MAXWIN; i++)
|
for (i = 0; i < MAXWIN; i++) {
|
||||||
if (wins[i] && (i != BASE_WINDOW)) {
|
if (i == BASE_WINDOW)
|
||||||
|
continue; /* handle wins[BASE_WINDOW] last */
|
||||||
|
if (wins[i]) {
|
||||||
#ifdef FREE_ALL_MEMORY
|
#ifdef FREE_ALL_MEMORY
|
||||||
free_window_info(wins[i], TRUE);
|
free_window_info(wins[i], TRUE);
|
||||||
free((genericptr_t) wins[i]);
|
free((genericptr_t) wins[i]);
|
||||||
#endif
|
#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)*/
|
#ifndef NO_TERMS /*(until this gets added to the window interface)*/
|
||||||
tty_shutdown(); /* cleanup termcap/terminfo/whatever */
|
tty_shutdown(); /* cleanup termcap/terminfo/whatever */
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user