Correctly handle mutation of the watcher list while iterating on them
Fixes #1227
This commit is contained in:
parent
2b01da530d
commit
5eef2b9105
|
@ -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)
|
||||
// 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,
|
||||
|
|
1
test/regression/1227-segfault-on-option-access/cmd
Normal file
1
test/regression/1227-segfault-on-option-access/cmd
Normal file
|
@ -0,0 +1 @@
|
|||
:test<ret>
|
1
test/regression/1227-segfault-on-option-access/in
Normal file
1
test/regression/1227-segfault-on-option-access/in
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
test/regression/1227-segfault-on-option-access/out
Normal file
1
test/regression/1227-segfault-on-option-access/out
Normal file
|
@ -0,0 +1 @@
|
|||
k
|
10
test/regression/1227-segfault-on-option-access/rc
Normal file
10
test/regression/1227-segfault-on-option-access/rc
Normal 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"
|
||||
}
|
Loading…
Reference in New Issue
Block a user