From 1f0caf4aedc74d884e95b6e005f4958cea841f85 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 23 Jul 2016 18:59:02 +0200 Subject: [PATCH] assault: Plug memory leak in spies sneaking ashore We free struct olist only for spies that get killed. Leaks since spies were added in 4.0.0. Signed-off-by: Markus Armbruster --- src/lib/commands/assa.c | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/lib/commands/assa.c b/src/lib/commands/assa.c index 2eb40b31..43b585c5 100644 --- a/src/lib/commands/assa.c +++ b/src/lib/commands/assa.c @@ -193,15 +193,14 @@ only_spies(struct combat off[], struct emp_qelem *olist) static void sneak_ashore(struct emp_qelem *olist, struct combat *def) { - struct emp_qelem *qp, *next; + struct emp_qelem *qp; struct ulist *llp; struct lndstr *lp; int rel; pr("Trying to sneak on shore...\n"); - for (qp = olist->q_forw; qp != olist; qp = next) { - next = qp->q_forw; + for (qp = olist->q_forw; qp != olist; qp = qp->q_forw) { llp = (struct ulist *)qp; lp = &llp->unit.land; rel = relations_with(def->own, player->cnum); @@ -210,7 +209,6 @@ sneak_ashore(struct emp_qelem *olist, struct combat *def) lp->lnd_x = def->x; lp->lnd_y = def->y; lp->lnd_ship = -1; - putland(lp->lnd_uid, lp); } else { pr("%s was spotted", prland(lp)); if (rel <= HOSTILE) { @@ -219,8 +217,6 @@ sneak_ashore(struct emp_qelem *olist, struct combat *def) def->own)); pr(" and was killed in the attempt.\n"); lp->lnd_effic = 0; - putland(lp->lnd_uid, lp); - lnd_put_one(llp); } else { wu(0, def->own, "%s spy spotted in %s.\n", cname(player->cnum), xyas(def->x, def->y, @@ -229,8 +225,9 @@ sneak_ashore(struct emp_qelem *olist, struct combat *def) lp->lnd_x = def->x; lp->lnd_y = def->y; lp->lnd_ship = -1; - putland(lp->lnd_uid, lp); } } } + + lnd_put(olist); }