mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-19 17:31:44 +03:00
Copy the list of hooks to run before iterating on them and running them
Running hooks could result in the hook list getting mutated, leading to potential crashes. Fixes #1222
This commit is contained in:
parent
38102595ef
commit
889a2144d4
@ -68,25 +68,28 @@ void HookManager::run_hook(StringView hook_name,
|
|||||||
auto start_time = profile ? Clock::now() : TimePoint{};
|
auto start_time = profile ? Clock::now() : TimePoint{};
|
||||||
|
|
||||||
auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>();
|
auto& disabled_hooks = context.options()["disabled_hooks"].get<Regex>();
|
||||||
bool hook_error = false;
|
Vector<std::pair<String, HookFunc>> hooks_to_run;
|
||||||
for (auto& hook : hook_list_it->value)
|
for (auto& hook : hook_list_it->value)
|
||||||
{
|
{
|
||||||
if (not hook.key.empty() and not disabled_hooks.empty() and
|
if (hook.key.empty() or disabled_hooks.empty() or
|
||||||
regex_match(hook.key.begin(), hook.key.end(), disabled_hooks))
|
regex_match(hook.key.begin(), hook.key.end(), disabled_hooks))
|
||||||
continue;
|
hooks_to_run.push_back({hook.key, hook.value});
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hook_error = false;
|
||||||
|
for (auto& hook : hooks_to_run)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (debug_flags & DebugFlags::Hooks)
|
if (debug_flags & DebugFlags::Hooks)
|
||||||
write_to_debug_buffer(format("hook {}/{}", hook_name, hook.key));
|
write_to_debug_buffer(format("hook {}/{}", hook_name, hook.first));
|
||||||
|
hook.second(param, context);
|
||||||
hook.value(param, context);
|
|
||||||
}
|
}
|
||||||
catch (runtime_error& err)
|
catch (runtime_error& err)
|
||||||
{
|
{
|
||||||
hook_error = true;
|
hook_error = true;
|
||||||
write_to_debug_buffer(format("error running hook {}({})/{}: {}",
|
write_to_debug_buffer(format("error running hook {}({})/{}: {}",
|
||||||
hook_name, param, hook.key, err.what()));
|
hook_name, param, hook.first, err.what()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user