From 94a6d9ecd9b42f6f08bef3701e96a99c32598b42 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Tue, 5 Jul 2022 07:43:16 +0200 Subject: [PATCH] avoid free-cycle --- src/unit/unit.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index ea5010813..08c4aeb58 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -553,21 +553,26 @@ void CUnit::Release(bool final) // removed, but fog of war calculations are still underway, where we want to // read a BoolFlag; there are more instances of this...) for (std::vector<COrder *>::iterator order = Orders.begin(); order != Orders.end(); ++order) { - delete *order; + COrder *orderToDelete = *order; + *order = NULL; + delete orderToDelete; } Orders.clear(); if (SavedOrder != NULL) { - delete SavedOrder; + COrder *order = SavedOrder; SavedOrder = NULL; + delete order; } if (NewOrder != NULL) { - delete NewOrder; + COrder *order = NewOrder; NewOrder = NULL; + delete order; } if (CriticalOrder != NULL) { - delete CriticalOrder; + COrder *order = CriticalOrder; CriticalOrder = NULL; + delete order; } // Remove the unit from the global units table.