From 5b1c73a2af75e92933b337a9d5d9691f3dd7c6b5 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 7 Aug 2020 12:27:46 +0200 Subject: [PATCH] Fixed valgrind issues. Signed-off-by: Deukhoofd --- src/Battling/EventHooks/EventHook.hpp | 11 +++++------ tests/BattleTests/EventHookTests.cpp | 1 + 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Battling/EventHooks/EventHook.hpp b/src/Battling/EventHooks/EventHook.hpp index 59628a2..833d412 100644 --- a/src/Battling/EventHooks/EventHook.hpp +++ b/src/Battling/EventHooks/EventHook.hpp @@ -39,9 +39,8 @@ namespace CreatureLib::Battling { free(_memory); if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; } size_t GetPosition() const noexcept { return _offset; } @@ -52,9 +51,9 @@ namespace CreatureLib::Battling { return; if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; + if (_offset + sizeof(T) >= _capacity) { _capacity += stepSize; auto newPtr = realloc(_memory, _capacity); @@ -74,9 +73,9 @@ namespace CreatureLib::Battling { void FinishListening() { if (_currentThread != nullptr && _currentThread->joinable()) { _currentThread->join(); - delete _currentThread; - _currentThread = nullptr; } + delete _currentThread; + _currentThread = nullptr; } private: diff --git a/tests/BattleTests/EventHookTests.cpp b/tests/BattleTests/EventHookTests.cpp index 668f091..5d540b5 100644 --- a/tests/BattleTests/EventHookTests.cpp +++ b/tests/BattleTests/EventHookTests.cpp @@ -41,5 +41,6 @@ TEST_CASE("Build and use event hook with different types", "[Battling]") { eventHook.Trigger(nullptr); eventHook.Trigger(nullptr, DamageSource::AttackDamage, 0, 0); eventHook.Trigger(nullptr); + eventHook.FinishListening(); } #endif \ No newline at end of file