Fixed valgrind issues.
continuous-integration/drone/push Build is passing Details

Signed-off-by: Deukhoofd <Deukhoofd@gmail.com>
This commit is contained in:
Deukhoofd 2020-08-07 12:27:46 +02:00
parent 208bb097dd
commit 5b1c73a2af
Signed by: Deukhoofd
GPG Key ID: F63E044490819F6F
2 changed files with 6 additions and 6 deletions

View File

@ -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,10 +73,10 @@ namespace CreatureLib::Battling {
void FinishListening() {
if (_currentThread != nullptr && _currentThread->joinable()) {
_currentThread->join();
}
delete _currentThread;
_currentThread = nullptr;
}
}
private:
void RunListeners(EventData* event) {

View File

@ -41,5 +41,6 @@ TEST_CASE("Build and use event hook with different types", "[Battling]") {
eventHook.Trigger<FaintEvent>(nullptr);
eventHook.Trigger<DamageEvent>(nullptr, DamageSource::AttackDamage, 0, 0);
eventHook.Trigger<FaintEvent>(nullptr);
eventHook.FinishListening();
}
#endif