]> granicus.if.org Git - nethack/commitdiff
Revert "plug a couple of memory leaks in sp_lev.c"
authorPatR <rankin@nethack.org>
Mon, 10 Feb 2020 23:44:16 +0000 (15:44 -0800)
committerPatR <rankin@nethack.org>
Mon, 10 Feb 2020 23:44:16 +0000 (15:44 -0800)
This reverts commit 1b7ac939306231a11ac44b24ef21b2ada40ecacc.

I just got a crash from within Lua when loading mine town and it
appears to be memory related, so back out the "plug leaks" commit
for the time being.

src/sp_lev.c

index 1872f1120b42c01f6fbc9d0a0f78143ca986d377..7317130d61d94b66dc37720295636a5a20511d97 100644 (file)
@@ -1,4 +1,4 @@
-/* NetHack 3.6 sp_lev.c        $NHDT-Date: 1581373396 2020/02/10 22:23:16 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.155 $ */
+/* NetHack 3.6 sp_lev.c        $NHDT-Date: 1580610435 2020/02/02 02:27:15 $  $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.153 $ */
 /*      Copyright (c) 1989 by Jean-Christophe Collet */
 /* NetHack may be freely redistributed.  See license for details. */
 
@@ -3597,12 +3597,11 @@ void
 selection_free(sel)
 struct selectionvar *sel;
 {
-    if (sel) {
-        Free(sel->map);
-        sel->map = NULL;
-        sel->wid = sel->hei = 0;
-        free((genericptr_t) sel);
-    }
+    if (!sel)
+        return;
+    Free(sel->map);
+    sel->map = NULL;
+    sel->wid = sel->hei = 0;
 }
 
 struct selectionvar *
@@ -3813,6 +3812,7 @@ int dir;
                 selection_setpoint(x, y, ov, 1);
 
     selection_free(tmp);
+    free(tmp);
 }
 
 static int FDECL((*selection_flood_check_func), (int, int));
@@ -3924,6 +3924,7 @@ boolean diagonals;
 #undef SEL_FLOOD_STACK
 #undef SEL_FLOOD_CHKDIR
     selection_free(tmp);
+    free(tmp);
 }
 
 /* McIlroy's Ellipse Algorithm */
@@ -4570,7 +4571,9 @@ struct selectionvar *ov;
     res = FALSE;
  gotitdone:
     selection_free(ov2);
+    free(ov2);
     selection_free(ov3);
+    free(ov3);
     return res;
 }
 
@@ -4603,19 +4606,19 @@ ensure_way_out()
 
     do {
         ret = TRUE;
-        for (x = 1; x < COLNO; x++)
+        for (x = 0; x < COLNO; x++)
             for (y = 0; y < ROWNO; y++)
                 if (ACCESSIBLE(levl[x][y].typ)
                     && !selection_getpoint(x, y, ov)) {
-                    if (generate_way_out_method(x, y, ov))
-                        selection_floodfill(ov, x, y, TRUE);
+                    if (generate_way_out_method(x,y, ov))
+                        selection_floodfill(ov, x,y, TRUE);
                     ret = FALSE;
                     goto outhere;
                 }
- outhere:
-        ;
+ outhere: ;
     } while (!ret);
     selection_free(ov);
+    free(ov);
 }
 
 int
@@ -5188,8 +5191,10 @@ int prop;
 
     if (sel) {
         selection_iterate(sel, sel_set_wall_property, (genericptr_t) &prop);
-        if (freesel)
+        if (freesel) {
             selection_free(sel);
+            free(sel);
+        }
     }
 }