Skip to content

Commit abadda4

Browse files
committed
signal_impl::clear(): Don't clear the slot list during signal emission
If signal_impl::clear() is called during signal emission, don't call slots_.clear(). Let signal_impl::sweep() erase all slots after the signal emission. Bug 784550
1 parent 661f12a commit abadda4

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

sigc++/signal_base.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ void signal_impl::clear()
5454
{
5555
// Don't let signal_impl::notify() erase the slots. It would invalidate the
5656
// iterator in the following loop.
57+
const bool during_signal_emission = exec_count_ > 0;
5758
const bool saved_deferred = deferred_;
5859
signal_exec exec(this);
5960

@@ -62,9 +63,15 @@ void signal_impl::clear()
6263
for (auto& slot : slots_)
6364
slot.disconnect();
6465

65-
deferred_ = saved_deferred;
66-
67-
slots_.clear();
66+
// Don't clear slots_ during signal emission. Provided deferred_ is true,
67+
// sweep() will be called from ~signal_exec() after signal emission,
68+
// and it will erase all disconnected slots.
69+
// https://bugzilla.gnome.org/show_bug.cgi?id=784550
70+
if (!during_signal_emission)
71+
{
72+
deferred_ = saved_deferred;
73+
slots_.clear();
74+
}
6875
}
6976

7077
signal_impl::size_type signal_impl::size() const noexcept

0 commit comments

Comments
 (0)