From 33cc4f880acd509309d1535faa8f460026564e8b Mon Sep 17 00:00:00 2001 From: Tim Felgentreff <timfelgentreff@gmail.com> Date: Tue, 15 Feb 2022 06:36:04 +0100 Subject: [PATCH] fix memory leak, thanks @Andrettin --- src/include/unit.h | 3 ++- src/unit/unit.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/include/unit.h b/src/include/unit.h index baa8af824..428630e02 100644 --- a/src/include/unit.h +++ b/src/include/unit.h @@ -134,7 +134,8 @@ enum _directions_ { class CUnit { public: - CUnit() : tilePos(-1, -1), pathFinderData(NULL), SavedOrder(NULL), NewOrder(NULL), CriticalOrder(NULL), Colors(-1) { Init(); } + CUnit() : tilePos(-1, -1), pathFinderData(NULL), SavedOrder(NULL), NewOrder(NULL), CriticalOrder(NULL), Colors(-1), + AutoCastSpell(NULL), SpellCoolDownTimers(NULL), Variable(NULL) { Init(); } ~CUnit(); void Init(); diff --git a/src/unit/unit.cpp b/src/unit/unit.cpp index f09ef5e94..cf7125c78 100644 --- a/src/unit/unit.cpp +++ b/src/unit/unit.cpp @@ -426,6 +426,7 @@ void CUnit::Init() Stats = NULL; CurrentSightRange = 0; + delete pathFinderData; pathFinderData = new PathFinderData; pathFinderData->input.SetUnit(*this); @@ -447,6 +448,7 @@ void CUnit::Init() RescuedFrom = NULL; memset(VisCount, 0, sizeof(VisCount)); memset(&Seen, 0, sizeof(Seen)); + delete Variable; Variable = NULL; TTL = 0; Threshold = 0; @@ -472,7 +474,9 @@ void CUnit::Init() NewOrder = NULL; delete CriticalOrder; CriticalOrder = NULL; + delete AutoCastSpell; AutoCastSpell = NULL; + delete SpellCoolDownTimers; SpellCoolDownTimers = NULL; AutoRepair = 0; Goal = NULL;