Correctly handle mutation of the watcher list while iterating on them

Fixes #1227
This commit is contained in:
Maxime Coste 2017-02-20 13:44:08 +00:00
parent 2b01da530d
commit 5eef2b9105
5 changed files with 20 additions and 2 deletions

View File

@ -108,8 +108,13 @@ void OptionManager::on_option_changed(const Option& option)
find_option(m_options, option.name()) != m_options.end())
return;
for (auto watcher : m_watchers)
watcher->on_option_changed(option);
// The watcher list might get mutated during calls to on_option_changed
auto watchers = m_watchers;
for (auto* watcher : watchers)
{
if (contains(m_watchers, watcher)) // make sure this watcher is still alive
watcher->on_option_changed(option);
}
}
CandidateList OptionsRegistry::complete_option_name(StringView prefix,

View File

@ -0,0 +1 @@
:test<ret>

View File

@ -0,0 +1 @@

View File

@ -0,0 +1 @@
k

View File

@ -0,0 +1,10 @@
decl str _
hook global BufCreate \*test\* %{
hook buffer BufSetOption _=.+ 'exec "i%opt{_}"'
}
def test %{
edit -scratch *test*
set buffer=*test* _ "k"
}