]> granicus.if.org Git - nethack/commitdiff
Extra checks when freeing objects and monsters
authorPasi Kallinen <paxed@alt.org>
Sun, 11 Oct 2015 18:40:38 +0000 (21:40 +0300)
committerPasi Kallinen <paxed@alt.org>
Sun, 11 Oct 2015 18:41:55 +0000 (21:41 +0300)
Just in case, so we don't leave objects or monsters inaccessible
by accident.

src/mkobj.c
src/mon.c
src/save.c

index 658b5ed5f3b64f3aba1383fe394b559ea7260c5e..321ea721283effdb3c719eaaef26195000a6ab91 100644 (file)
@@ -1943,6 +1943,10 @@ struct obj *obj;
 {
     if (obj->where != OBJ_FREE)
         panic("dealloc_obj: obj not free");
+    if (obj->nobj)
+        panic("dealloc_obj with nobj");
+    if (obj->cobj)
+        panic("dealloc_obj with cobj");
 
     /* free up any timers attached to the object */
     if (obj->timed)
index 4e5be3f96606427f0a4178e7072d22c1c81d832b..3a75573a71a63fdc88b9c10b8b0b7ce99a2182a3 100644 (file)
--- a/src/mon.c
+++ b/src/mon.c
@@ -1426,6 +1426,7 @@ dmonsfree()
         freetmp = *mtmp;
         if (freetmp->mhp <= 0 && !freetmp->isgd) {
             *mtmp = freetmp->nmon;
+            freetmp->nmon = NULL;
             dealloc_monst(freetmp);
             count++;
         } else
@@ -1603,6 +1604,8 @@ void
 dealloc_monst(mon)
 struct monst *mon;
 {
+    if (mon->nmon)
+        panic("dealloc_monst with nmon");
     if (mon->mextra)
         dealloc_mextra(mon->mextra);
     free((genericptr_t) mon);
index 8ab8225de4d23afa96439b2122967aacef72b82a..e1c737dec6d8324fcf858dd8c3b7565a69594c60 100644 (file)
@@ -1051,6 +1051,8 @@ register struct obj *otmp;
                 context.spbook.book = (struct obj *) 0;
             }
             otmp->where = OBJ_FREE; /* set to free so dealloc will work */
+            otmp->nobj = NULL;      /* nobj saved into otmp2 */
+            otmp->cobj = NULL;      /* contents handled above */
             otmp->timed = 0;        /* not timed any more */
             otmp->lamplit = 0;      /* caller handled lights */
             dealloc_obj(otmp);
@@ -1149,6 +1151,7 @@ register struct monst *mtmp;
                 context.polearm.m_id = mtmp->m_id;
                 context.polearm.hitmon = NULL;
             }
+            mtmp->nmon = NULL;  /* nmon saved into mtmp2 */
             dealloc_monst(mtmp);
         }
         mtmp = mtmp2;