From 31bce71c3348ce69a6b4a44d3124f958e475b73b Mon Sep 17 00:00:00 2001 From: DarthArgus Date: Wed, 30 Nov 2016 22:16:33 +0000 Subject: [PATCH] this is a better way of nuking saved snapshots --- .../serverDatabase/src/shared/Persister.cpp | 39 +++++++++++++++---- .../serverDatabase/src/shared/Snapshot.cpp | 2 +- .../src/shared/TaskSaveSnapshot.cpp | 3 ++ 3 files changed, 36 insertions(+), 8 deletions(-) diff --git a/engine/server/library/serverDatabase/src/shared/Persister.cpp b/engine/server/library/serverDatabase/src/shared/Persister.cpp index 1c45f1b2..30f951c6 100755 --- a/engine/server/library/serverDatabase/src/shared/Persister.cpp +++ b/engine/server/library/serverDatabase/src/shared/Persister.cpp @@ -174,15 +174,44 @@ Persister::~Persister() { DEBUG_FATAL(taskQueue,("Call shutdown() before deleting Persister.\n")); - ServerSnapshotMap::iterator i; - for (i=m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i) + for (auto i = m_currentSnapshots.begin(); i!=m_currentSnapshots.end(); ++i) { delete i->second; - for (i=m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i) + i->second = nullptr; + } + + for (auto i = m_newObjectSnapshots.begin(); i!=m_newObjectSnapshots.end(); ++i) { delete i->second; + i->second = nullptr; + } + + for (auto i = m_newCharacterSnapshots.begin(); i!=m_newCharacterSnapshots.end(); ++i) { + delete i->second; + i->second = nullptr; + } + + for (auto i = m_objectSnapshotMap.begin(); i!=m_objectSnapshotMap.end(); ++i) { + delete i->second; + i->second = nullptr; + } + + for (auto i = m_savingSnapshots.begin(); i!=m_savingSnapshots.end(); ++i) { + delete *i; + *i = nullptr; + } + + for (auto i = m_savingCharacterSnapshots.begin(); i!=m_savingCharacterSnapshots.end(); ++i) { + delete *i; + *i = nullptr; + } m_currentSnapshots.clear(); m_newObjectSnapshots.clear(); m_objectSnapshotMap.clear(); + + delete m_messageSnapshot; + delete m_commoditiesSnapshot; + delete m_arbitraryGameDataSnapshot; + m_messageSnapshot = nullptr; m_commoditiesSnapshot = nullptr; m_arbitraryGameDataSnapshot = nullptr; @@ -602,8 +631,6 @@ void Persister::saveCompleted(Snapshot *completedSnapshot) SnapshotListType::iterator i=std::remove(m_savingSnapshots.begin(),m_savingSnapshots.end(),completedSnapshot); if (i!=m_savingSnapshots.end()) { - delete completedSnapshot; - m_savingSnapshots.erase(i, m_savingSnapshots.end()); if (m_savingSnapshots.empty() && ConfigServerDatabase::getReportSaveTimes()) { @@ -636,8 +663,6 @@ void Persister::saveCompleted(Snapshot *completedSnapshot) { SnapshotListType::iterator j=std::remove(m_savingCharacterSnapshots.begin(),m_savingCharacterSnapshots.end(),completedSnapshot); DEBUG_FATAL(i==m_savingCharacterSnapshots.end(),("Programmer bug: SaveCompleted() called with a snapshot that wasn't in m_savingSnapshots or m_savingCharacterSnapshots.")); - delete completedSnapshot; - m_savingCharacterSnapshots.erase(j, m_savingCharacterSnapshots.end()); DEBUG_REPORT_LOG(ConfigServerDatabase::getReportSaveTimes(),("New character save completed\n")); } diff --git a/engine/server/library/serverDatabase/src/shared/Snapshot.cpp b/engine/server/library/serverDatabase/src/shared/Snapshot.cpp index c0f0b490..17209379 100755 --- a/engine/server/library/serverDatabase/src/shared/Snapshot.cpp +++ b/engine/server/library/serverDatabase/src/shared/Snapshot.cpp @@ -54,7 +54,7 @@ Snapshot::~Snapshot() m_customStepList.clear(); ++ms_deletionCount; - LOG("Snapshot",("Deleted snapshot. %i outstanding, %i created, %i deleted", ms_creationCount-ms_deletionCount,ms_creationCount,ms_deletionCount)); + LOG("Snapshot",("Deleted snapshot. %i outstanding, %i created, %i deleted", ms_creationCount-ms_deletionCount,ms_creationCount,ms_deletionCount)); } // ---------------------------------------------------------------------- diff --git a/engine/server/library/serverDatabase/src/shared/TaskSaveSnapshot.cpp b/engine/server/library/serverDatabase/src/shared/TaskSaveSnapshot.cpp index 2222b250..982de1ef 100755 --- a/engine/server/library/serverDatabase/src/shared/TaskSaveSnapshot.cpp +++ b/engine/server/library/serverDatabase/src/shared/TaskSaveSnapshot.cpp @@ -30,6 +30,9 @@ void TaskSaveSnapshot::onComplete() { m_snapshot->saveCompleted(); Persister::getInstance().saveCompleted(m_snapshot); + + delete m_snapshot; + m_snapshot = nullptr; } // ======================================================================