From 6d00fc65c073637f1e93a10180d80a1c8564d5f0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 25 Jul 2022 21:08:04 +0200 Subject: [PATCH] fix memory leak --- .../datapoollocal/LocalDataPoolManager.cpp | 24 ++++--------------- src/fsfw/datapoollocal/LocalDataPoolManager.h | 4 ++-- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp index 2ab737bf..45ef9567 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.cpp +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.cpp @@ -291,11 +291,7 @@ ReturnValue_t LocalDataPoolManager::addUpdateToStore(HousekeepingSnapshot& updat void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, MarkChangedIF* toReset) { - if (hkUpdateResetList == nullptr) { - /* Config error */ - return; - } - HkUpdateResetList& listRef = *hkUpdateResetList; + HkUpdateResetList& listRef = hkUpdateResetList; for (auto& changeInfo : listRef) { if (changeInfo.dataType != type) { continue; @@ -326,11 +322,7 @@ void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, } void LocalDataPoolManager::resetHkUpdateResetHelper() { - if (hkUpdateResetList == nullptr) { - return; - } - - for (auto& changeInfo : *hkUpdateResetList) { + for (auto& changeInfo : hkUpdateResetList) { changeInfo.currentUpdateCounter = changeInfo.updateCounter; } } @@ -442,11 +434,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessage( } void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, DataId dataId) { - if (hkUpdateResetList == nullptr) { - hkUpdateResetList = new std::vector(); - } - - for (auto& updateResetStruct : *hkUpdateResetList) { + for (auto& updateResetStruct : hkUpdateResetList) { if (dataType == DataType::DATA_SET) { if (updateResetStruct.dataId.sid == dataId.sid) { updateResetStruct.updateCounter++; @@ -470,7 +458,7 @@ void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, D } else { hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId; } - hkUpdateResetList->push_back(hkUpdateResetHelper); + hkUpdateResetList.push_back(hkUpdateResetHelper); } ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(CommandMessage* message) { @@ -824,9 +812,7 @@ void LocalDataPoolManager::clearReceiversList() { /* Clear the vector completely and releases allocated memory. */ HkReceivers().swap(hkReceivers); /* Also clear the reset helper if it exists */ - if (hkUpdateResetList != nullptr) { - HkUpdateResetList().swap(*hkUpdateResetList); - } + HkUpdateResetList().swap(hkUpdateResetList); } MutexIF* LocalDataPoolManager::getLocalPoolMutex() { return this->mutex; } diff --git a/src/fsfw/datapoollocal/LocalDataPoolManager.h b/src/fsfw/datapoollocal/LocalDataPoolManager.h index 041a4b05..998ca03b 100644 --- a/src/fsfw/datapoollocal/LocalDataPoolManager.h +++ b/src/fsfw/datapoollocal/LocalDataPoolManager.h @@ -297,8 +297,8 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces using HkUpdateResetList = std::vector; /** This list is used to manage creating multiple update packets and only resetting - the update flag if all of them were created. Will only be created when needed. */ - HkUpdateResetList* hkUpdateResetList = nullptr; + the update flag if all of them were created. */ + HkUpdateResetList hkUpdateResetList = HkUpdateResetList(); /** This is the map holding the actual data. Should only be initialized * once ! */