]> git.pond.sub.org Git - empserver/commitdiff
Fix memory leaks in plane interception
authorMarkus Armbruster <armbru@pond.sub.org>
Sat, 22 Mar 2008 18:43:38 +0000 (19:43 +0100)
committerMarkus Armbruster <armbru@pond.sub.org>
Wed, 26 Mar 2008 21:08:15 +0000 (22:08 +0100)
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

index 6a4013d63dcdaf88b455d19833ca33be62275db1..644fe78b8618337c3d5f7e3bbd72028719430eb1 100644 (file)
@@ -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