fix memory leak

This commit is contained in:
Robin Müller 2022-07-25 21:08:04 +02:00
parent 7d87274844
commit 6d00fc65c0
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
2 changed files with 7 additions and 21 deletions

View File

@ -291,11 +291,7 @@ ReturnValue_t LocalDataPoolManager::addUpdateToStore(HousekeepingSnapshot& updat
void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId, void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId,
MarkChangedIF* toReset) { MarkChangedIF* toReset) {
if (hkUpdateResetList == nullptr) { HkUpdateResetList& listRef = hkUpdateResetList;
/* Config error */
return;
}
HkUpdateResetList& listRef = *hkUpdateResetList;
for (auto& changeInfo : listRef) { for (auto& changeInfo : listRef) {
if (changeInfo.dataType != type) { if (changeInfo.dataType != type) {
continue; continue;
@ -326,11 +322,7 @@ void LocalDataPoolManager::handleChangeResetLogic(DataType type, DataId dataId,
} }
void LocalDataPoolManager::resetHkUpdateResetHelper() { void LocalDataPoolManager::resetHkUpdateResetHelper() {
if (hkUpdateResetList == nullptr) { for (auto& changeInfo : hkUpdateResetList) {
return;
}
for (auto& changeInfo : *hkUpdateResetList) {
changeInfo.currentUpdateCounter = changeInfo.updateCounter; changeInfo.currentUpdateCounter = changeInfo.updateCounter;
} }
} }
@ -442,11 +434,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForVariableUpdateMessage(
} }
void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, DataId dataId) { void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, DataId dataId) {
if (hkUpdateResetList == nullptr) { for (auto& updateResetStruct : hkUpdateResetList) {
hkUpdateResetList = new std::vector<struct HkUpdateResetHelper>();
}
for (auto& updateResetStruct : *hkUpdateResetList) {
if (dataType == DataType::DATA_SET) { if (dataType == DataType::DATA_SET) {
if (updateResetStruct.dataId.sid == dataId.sid) { if (updateResetStruct.dataId.sid == dataId.sid) {
updateResetStruct.updateCounter++; updateResetStruct.updateCounter++;
@ -470,7 +458,7 @@ void LocalDataPoolManager::handleHkUpdateResetListInsertion(DataType dataType, D
} else { } else {
hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId; hkUpdateResetHelper.dataId.localPoolId = dataId.localPoolId;
} }
hkUpdateResetList->push_back(hkUpdateResetHelper); hkUpdateResetList.push_back(hkUpdateResetHelper);
} }
ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(CommandMessage* message) { ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage(CommandMessage* message) {
@ -824,9 +812,7 @@ void LocalDataPoolManager::clearReceiversList() {
/* Clear the vector completely and releases allocated memory. */ /* Clear the vector completely and releases allocated memory. */
HkReceivers().swap(hkReceivers); HkReceivers().swap(hkReceivers);
/* Also clear the reset helper if it exists */ /* Also clear the reset helper if it exists */
if (hkUpdateResetList != nullptr) { HkUpdateResetList().swap(hkUpdateResetList);
HkUpdateResetList().swap(*hkUpdateResetList);
}
} }
MutexIF* LocalDataPoolManager::getLocalPoolMutex() { return this->mutex; } MutexIF* LocalDataPoolManager::getLocalPoolMutex() { return this->mutex; }

View File

@ -297,8 +297,8 @@ class LocalDataPoolManager : public ProvidesDataPoolSubscriptionIF, public Acces
using HkUpdateResetList = std::vector<struct HkUpdateResetHelper>; using HkUpdateResetList = std::vector<struct HkUpdateResetHelper>;
/** This list is used to manage creating multiple update packets and only resetting /** 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. */ the update flag if all of them were created. */
HkUpdateResetList* hkUpdateResetList = nullptr; HkUpdateResetList hkUpdateResetList = HkUpdateResetList();
/** This is the map holding the actual data. Should only be initialized /** This is the map holding the actual data. Should only be initialized
* once ! */ * once ! */