Fix memory leaks in statistics handling PR#1835 & fixed conflicts
@@ -83,9 +83,11 @@ int Ingest::createStatsDbEntry(const string& assetName)
if (!m_storage.insertTable("statistics", newStatsEntry))
{
m_logger->error("%s:%d : Insert new row into statistics table failed, newStatsEntry='%s'", __FUNCTION__, __LINE__, newStatsEntry.toJSON().c_str());
+ delete result;
return -1;
}
}
+ delete result;
}
catch (...)
{
@@ -159,8 +161,7 @@ void Ingest::updateStats()
statsUpdates.emplace_back(updateValue, wPluginStat);
}
- try
- {
+ try {
int rv = m_storage.updateTable("statistics", statsUpdates);
if (rv<0)
@@ -168,18 +169,17 @@ void Ingest::updateStats()
else
{
m_discardedReadings=0;
- for (auto it = statsUpdates.begin(); it != statsUpdates.end(); ++it)
- {
- delete it->first;
- delete it->second;
- }
statsPendingEntries.clear();
}
}
- catch (...)
- {
+ catch (...) {
Logger::getLogger()->info("%s:%d : Statistics table update failed, will retry on next iteration", __FUNCTION__, __LINE__);
}
+ for (auto it = statsUpdates.begin(); it != statsUpdates.end(); ++it)
+ {
+ delete it->first;
+ delete it->second;
+ }
}
/**
