From 05a0d10097ed76fa2b664beb8926a2054fe99389 Mon Sep 17 00:00:00 2001 From: PatR Date: Tue, 4 Jun 2019 14:54:58 -0700 Subject: [PATCH] plug montraits() memory leek If a corpse with a revive timer included obj->oextra->omonst for remembering the original monster (I think all corpses do these days) and makemon() failed to create a new monster when the timer expired, the copy of the original wasn't freed. makemon() will fail if there is no room for the monster. --- doc/fixes36.3 | 3 ++- src/zap.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/doc/fixes36.3 b/doc/fixes36.3 index 1c28ed086..4df27bcc5 100644 --- a/doc/fixes36.3 +++ b/doc/fixes36.3 @@ -1,4 +1,4 @@ -$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.37 $ $NHDT-Date: 1559679496 2019/06/04 20:18:16 $ +$NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.38 $ $NHDT-Date: 1559685281 2019/06/04 21:54:41 $ This fixes36.3 file is here to capture information about updates in the 3.6.x lineage following the release of 3.6.2 in May 2019. Please note, however, @@ -50,6 +50,7 @@ similar perm_invent issue when lock state known and/or contents known become set for carried container blessed scroll of remove curse read while confused might be shown to operate on itself by perm_invent after player is told that it has disappeared +fix memory leak if corpse auto-revival attempt failed ("you feel less hassled") Fixes to Post-3.6.2 Problems that Were Exposed Via git Repository diff --git a/src/zap.c b/src/zap.c index d054b2a14..724dc3189 100644 --- a/src/zap.c +++ b/src/zap.c @@ -1,4 +1,4 @@ -/* NetHack 3.6 zap.c $NHDT-Date: 1559675618 2019/06/04 19:13:38 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.309 $ */ +/* NetHack 3.6 zap.c $NHDT-Date: 1559685281 2019/06/04 21:54:41 $ $NHDT-Branch: NetHack-3.6 $:$NHDT-Revision: 1.310 $ */ /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ /*-Copyright (c) Robert Patrick Rankin, 2013. */ /* NetHack may be freely redistributed. See license for details. */ @@ -584,11 +584,8 @@ struct obj *obj; coord *cc; boolean adjacentok; /* False: at obj's spot only, True: nearby is allowed */ { - struct monst *mtmp = (struct monst *) 0; - struct monst *mtmp2 = (struct monst *) 0; + struct monst *mtmp, *mtmp2 = has_omonst(obj) ? get_mtraits(obj, TRUE) : 0; - if (has_omonst(obj)) - mtmp2 = get_mtraits(obj, TRUE); if (mtmp2) { /* save_mtraits() validated mtmp2->mnum */ mtmp2->data = &mons[mtmp2->mnum]; @@ -597,8 +594,12 @@ boolean adjacentok; /* False: at obj's spot only, True: nearby is allowed */ mtmp = makemon(mtmp2->data, cc->x, cc->y, (NO_MINVENT | MM_NOWAIT | MM_NOCOUNTBIRTH | (adjacentok ? MM_ADJACENTOK : 0))); - if (!mtmp) - return mtmp; + if (!mtmp) { + /* mtmp2 is a copy of obj's object->oextra->omonst extension + and is not on the map or on any monst lists */ + dealloc_monst(mtmp2); + return (struct monst *) 0; + } /* heal the monster */ if (mtmp->mhpmax > mtmp2->mhpmax && is_rider(mtmp2->data))