Detect recursive hook run and abort in that case

Fixes #709
This commit is contained in:
Maxime Coste 2016-06-27 20:55:07 +01:00
parent 014cd50883
commit 089eaa52e0
2 changed files with 11 additions and 0 deletions

View File

@ -51,6 +51,16 @@ void HookManager::run_hook(StringView hook_name,
if (hook_list_it == m_hook.end()) if (hook_list_it == m_hook.end())
return; return;
if (contains(m_running_hooks, std::make_pair(hook_name, param)))
{
auto error = format("recursive call of hook {}/{}, aborting", hook_name, param);
write_to_debug_buffer(error);
throw runtime_error(std::move(error));
}
m_running_hooks.emplace_back(hook_name, param);
auto pop_running_hook = on_scope_end([this]{ m_running_hooks.pop_back(); });
using Clock = std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
using TimePoint = Clock::time_point; using TimePoint = Clock::time_point;

View File

@ -30,6 +30,7 @@ private:
SafePtr<HookManager> m_parent; SafePtr<HookManager> m_parent;
IdMap<IdMap<HookFunc, MemoryDomain::Hooks>, MemoryDomain::Hooks> m_hook; IdMap<IdMap<HookFunc, MemoryDomain::Hooks>, MemoryDomain::Hooks> m_hook;
mutable Vector<std::pair<StringView, StringView>> m_running_hooks;
}; };
} }