]> granicus.if.org Git - nethack/commitdiff
X11 memory management
authorPatR <rankin@nethack.org>
Tue, 2 Feb 2016 23:19:31 +0000 (15:19 -0800)
committerPatR <rankin@nethack.org>
Tue, 2 Feb 2016 23:19:31 +0000 (15:19 -0800)
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.

include/winX.h
win/X11/winmap.c
win/X11/winmisc.c

index dcd588d6ffd13e388739d9d674e62a260e271f3d..536ec84d0b67dae7da12605a00bd2412d2e998a6 100644 (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));
index 28d973e0b5590900f35b135e870d43e730dcbc87..d2b79cf73ea303c9a5dfb86907b4c827a8855823 100644 (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 */
index 960577e14ce78ed1e1ad09bd7f7a408e8e2ef41f..04564f19cd36ff598ae0340673253f3306818320 100644 (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*/