From 1acc272718f445d39b15332c38dd4e7532345724 Mon Sep 17 00:00:00 2001 From: PatR Date: Mon, 20 Jan 2025 10:24:12 -0800 Subject: [PATCH] fix memory leak for knight's starting pony makemon() has a 1% chance to bestow a worn saddle when creating any rideable monster. If that chance kicked in on a knight's starting pony, an extra saddle would end up being created but not worn nor in inventory nor on floor so not be freed when the game ended. That 1% chance also overrode saddle suppression for pauper knights. There wouldn't be any extra saddle but their pony could start with one, against intent. Have makedog() (which is only used for starting pet) tell makemon() to suppress inventory when creating the initial pet. --- doc/fixes3-7-0.txt | 3 +++ src/dog.c | 9 +++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index a4db52429..befaae8f6 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2088,6 +2088,9 @@ shop bug: buying a container with unpaid items in it could produce impossible "unpaid_cost: object not on any bill" warnings when walking into/against a locked closed door, 'autounlock'==kick didn't execute kick when player answered yes to "Door is locked. Kick it?" +having a 1% chance of creating rideable monsters with worn saddle gave knights + a 1% chance of creating an extra saddle for starting pony; it wasn't + tracked with other objects so produced a trivial memory leak Fixes to 3.7.0-x Platform and/or Interface Problems Exposed Via git Repository diff --git a/src/dog.c b/src/dog.c index a80b3679d..7fffb6da9 100644 --- a/src/dog.c +++ b/src/dog.c @@ -217,7 +217,12 @@ makedog(void) petname = "Sirius"; /* Orion's dog */ } - mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG); + /* specifying NO_MINVENT prevents makemon() from having a 1% chance + of creating a pony with an already worn saddle; dogs and cats + aren't affected because they don't have any initial inventory + [if anybody adds stranger pets that are expected to have such, + they'll need to modify this] */ + mtmp = makemon(&mons[pettype], u.ux, u.uy, MM_EDOG | NO_MINVENT); if (!mtmp) return ((struct monst *) 0); /* pets were genocided [how?] */ @@ -225,7 +230,7 @@ makedog(void) if (!svc.context.startingpet_mid) { svc.context.startingpet_mid = mtmp->m_id; if (!u.uroleplay.pauper) { - /* initial horses already wear saddle (unless hero is a pauper) */ + /* initial horses start wearing a saddle (pauper hero excluded) */ if (pettype == PM_PONY && (otmp = mksobj(SADDLE, TRUE, FALSE)) != 0) { /* pseudo initial inventory; saddle is not actually in hero's