From 24e7bce0cf3777e5dbab5be8331e5590cb4cc301 Mon Sep 17 00:00:00 2001
From: Marko Lindqvist <cazfi74@gmail.com>
Date: Mon, 11 Nov 2024 03:54:01 +0200
Subject: [PATCH 86/86] Free unit act_prob_cache if the action turned out to be
 illegal

Reporte by Alain BKR

See RM #939

Signed-off-by: Marko Lindqvist <cazfi74@gmail.com>
---
 client/control.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/client/control.c b/client/control.c
index 244e26326a..b58f675905 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1050,6 +1050,8 @@ void set_units_in_combat(struct unit *pattacker, struct unit *pdefender)
 **************************************************************************/
 void action_selection_no_longer_in_progress(const int old_actor_id)
 {
+  struct unit *old_actor_unit;
+
   /* IDENTITY_NUMBER_ZERO is accepted for cases where the unit is gone
    * without a trace. */
   fc_assert_msg(old_actor_id == action_selection_in_progress_for
@@ -1058,6 +1060,12 @@ void action_selection_no_longer_in_progress(const int old_actor_id)
                 "Decision taken for %d but selection is for %d.",
                 old_actor_id, action_selection_in_progress_for);
 
+  old_actor_unit = game_unit_by_number(old_actor_id);
+  if (old_actor_unit != NULL
+      && old_actor_unit->client.act_prob_cache != NULL) {
+    FC_FREE(old_actor_unit->client.act_prob_cache);
+  }
+
   /* Stop objecting to allowing the next unit to ask. */
   action_selection_in_progress_for = IDENTITY_NUMBER_ZERO;
 
-- 
2.45.2

