From 6fe12d0b7fbeb03f9766cbdc6fda9a0763faec44 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Sat, 22 Mar 2008 19:43:38 +0100 Subject: [PATCH] Fix memory leaks in plane interception Interception builds lists of planes that could intercept. Only list nodes for missiles were freed. Broken since BSD Empire 1.1. The fix frees interceptors that actually intercepted when ac_intercept() returns, and the interceptors that didn't when ac_encounter() returns. The latter introduces a small bug: it passes planes that didn't fly to pln_put(). pln_put() expects only planes that actually took off. Same bug exists in air defense missions. Luckily, it has no ill effects. To be fixed soon. --- src/lib/subs/aircombat.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/lib/subs/aircombat.c b/src/lib/subs/aircombat.c index 6a4013d6..644fe78b 100644 --- a/src/lib/subs/aircombat.c +++ b/src/lib/subs/aircombat.c @@ -269,11 +269,8 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, if (changed) writemap(player->cnum); /* Now, if the bomber and escort lists are empty, we are done */ - if (QEMPTY(bomb_list) && QEMPTY(esc_list)) { - if (mission_flags & P_A) - free_shiplist(&head); - return; - } + if (QEMPTY(bomb_list) && QEMPTY(esc_list)) + goto out; /* Something made it through */ /* Go figure out if there are ships in this sector, and who's they are */ @@ -355,8 +352,13 @@ ac_encounter(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, } } } +out: if (mission_flags & P_A) free_shiplist(&head); + for (cn = 1; cn < MAXNOC; cn++) { + if (gotilist[cn]) + pln_put(&ilist[cn]); + } } static int @@ -504,6 +506,7 @@ ac_intercept(struct emp_qelem *bomb_list, struct emp_qelem *esc_list, ac_airtoair(bomb_list, &int_list); PR(plane_owner, "\n"); PR(def_own, "\n"); + pln_put(&int_list); } void