From ba3f439bcb7523776c8c064333d1c3aada46d59c Mon Sep 17 00:00:00 2001 From: Naios Date: Thu, 3 Mar 2016 01:27:02 +0100 Subject: Core/Database: Close the databases correctly when the DBUpdater fails * Also fixes a memory leak spotted by Aokromes (cherry picked from commit 7d3cffc297b6a1e24faf64a19b5167609ad8abbf) --- src/server/database/Database/DatabaseLoader.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/server/database/Database/DatabaseLoader.h') diff --git a/src/server/database/Database/DatabaseLoader.h b/src/server/database/Database/DatabaseLoader.h index be3bfd6fdb7..1b31d3691c4 100644 --- a/src/server/database/Database/DatabaseLoader.h +++ b/src/server/database/Database/DatabaseLoader.h @@ -21,8 +21,9 @@ #include "DatabaseWorkerPool.h" #include "DatabaseEnv.h" -#include #include +#include +#include // A helper class to initiate all database worker pools, // handles updating, delays preparing of statements and cleans up on failure. @@ -57,16 +58,18 @@ private: bool PrepareStatements(); using Predicate = std::function; + using Closer = std::function; - static bool Process(std::stack& stack); + // Invokes all functions in the given queue and closes the databases on errors. + // Returns false when there was an error. + bool Process(std::queue& queue); std::string const _logger; bool const _autoSetup; uint32 const _updateFlags; - std::stack>> _open; - std::stack> _close; - std::stack _populate, _update, _prepare; + std::queue _open, _populate, _update, _prepare; + std::stack _close; }; #endif // DatabaseLoader_h__ -- cgit v1.2.3