X11 memory management

The big memory allocation for tiles that was unfreed according to
heaputil was actually freed by X according to a comment in the code.
But free it explicitly for #if MONITOR_HEAP so that the alloc/free
tracking stays accurate.

Also, the cached extended commands menu was not being freed, so take
care of that.  I wasn't sure where to handle it; I ended up making it
happen when the map window is torn down.
This commit is contained in:
PatR
2016-02-02 15:19:31 -08:00
parent 309ad50f61
commit 64112c8464
3 changed files with 26 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winX.h $NHDT-Date: 1453447524 2016/01/22 07:25:24 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.19 $ */
/* NetHack 3.6 winX.h $NHDT-Date: 1454455159 2016/02/02 23:19:19 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.21 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -331,6 +331,7 @@ E void FDECL(algn_key,
E void FDECL(ec_delete, (Widget, XEvent *, String *, Cardinal *));
E void FDECL(ec_key, (Widget, XEvent *, String *,
Cardinal *)); /* extended command action */
E void NDECL(release_extended_cmds);
/* ### winstatus.c ### */
E void FDECL(create_status_window, (struct xwindow *, BOOLEAN_P, Widget));

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winmap.c $NHDT-Date: 1447844616 2015/11/18 11:03:36 $ $NHDT-Branch: master $:$NHDT-Revision: 1.25 $ */
/* NetHack 3.6 winmap.c $NHDT-Date: 1454455161 2016/02/02 23:19:21 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.26 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -235,6 +235,11 @@ post_process_tiles()
tile_image, 0, 0, 0, 0, /* src, dest top left */
width, height);
#ifdef MONITOR_HEAP
/* if we let XDestroyImage() handle it, our tracking will be off */
if (tile_image->data)
free((genericptr_t) tile_image->data), tile_image->data = 0;
#endif
XDestroyImage(tile_image); /* data bytes free'd also */
tile_image = 0;
@@ -1610,6 +1615,11 @@ struct xwindow *wp;
(XtPointer) 0);
else
wp->type = NHW_NONE; /* allow re-use */
/* when map goes away, presumably we're exiting, so get rid of the
cached extended commands menu (if we aren't actually exiting, it
will get recreated if needed again) */
release_extended_cmds();
}
boolean exit_x_event; /* exit condition for the event loop */

View File

@@ -1,4 +1,4 @@
/* NetHack 3.6 winmisc.c $NHDT-Date: 1452593730 2016/01/12 10:15:30 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.15 $ */
/* NetHack 3.6 winmisc.c $NHDT-Date: 1454455162 2016/02/02 23:19:22 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.20 $ */
/* Copyright (c) Dean Luick, 1992 */
/* NetHack may be freely redistributed. See license for details. */
@@ -585,12 +585,8 @@ X11_player_selection()
int
X11_get_ext_cmd()
{
static Boolean initialized = False;
if (!initialized) {
if (!extended_commands)
init_extended_commands_popup();
initialized = True;
}
extended_cmd_selected = -1; /* reset selected value */
@@ -604,6 +600,15 @@ X11_get_ext_cmd()
return extended_cmd_selected;
}
void
release_extended_cmds()
{
if (extended_commands) {
XtDestroyWidget(extended_command_popup);
free((genericptr_t) extended_commands), extended_commands = 0;
}
}
/* End global functions =====================================================
*/
@@ -1161,3 +1166,5 @@ Widget *formp; /* return */
return popup;
}
/*winmisc.c*/