From 498c02fa8316a5177ccb3f2f6476971e7c7aceea Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Thu, 14 Jul 2016 21:29:04 +0300 Subject: [PATCH] Properly terminate all command controllers and release their resources and callbacks to prevent a server crash at shutdown since callbacks were not released. --- source/Command.cpp | 2 +- source/Command.hpp | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/source/Command.cpp b/source/Command.cpp index 54ad3ed8..6c1a9908 100644 --- a/source/Command.cpp +++ b/source/Command.cpp @@ -1193,7 +1193,7 @@ void Register_Command(HSQUIRRELVM vm) */ void TerminateCommands() { - Cmd::Controller::ClearAll(); + Cmd::Controller::Terminate(); } } // Namespace:: SqMod diff --git a/source/Command.hpp b/source/Command.hpp index 19b5327a..65345538 100644 --- a/source/Command.hpp +++ b/source/Command.hpp @@ -504,13 +504,17 @@ protected: public: /* -------------------------------------------------------------------------------------------- - * Clear the command listeners from all controllers. + * Terminate the all controllers by releasing their command listeners and callbacks. */ - static void ClearAll() + static void Terminate() { for (auto & ctr : s_Controllers) { + // Clear the command listeners ctr->Clear(); + // Release the script callbacks, if any + ctr->m_OnFail.ReleaseGently(); + ctr->m_OnAuth.ReleaseGently(); } }