util: fix segfault in UtilSignal/DisconnectSelfInHandler test case
refs #2302
Change-Id: I354c39b3ebdef2ed0f0403c15448e23856ab47b3
diff --git a/src/util/signal-signal.hpp b/src/util/signal-signal.hpp
index 6fd6c70..444c702 100644
--- a/src/util/signal-signal.hpp
+++ b/src/util/signal-signal.hpp
@@ -56,6 +56,7 @@
/** \brief connects a handler to the signal
* \note If invoked from a handler, the new handler won't receive the current emitted signal.
+ * \warning The handler is permitted to disconnect itself, but it must ensure its validity.
*/
Connection
connect(const Handler& handler);
diff --git a/tests/unit-tests/util/signal.cpp b/tests/unit-tests/util/signal.cpp
index 0de06a2..afb4980 100644
--- a/tests/unit-tests/util/signal.cpp
+++ b/tests/unit-tests/util/signal.cpp
@@ -286,11 +286,13 @@
int hit = 0;
Connection connection;
- connection = so.sig.connect([&] {
+ connection = so.sig.connect(bind([&] (SignalOwner0& so) {
++hit;
connection.disconnect();
BOOST_CHECK_EQUAL(so.isSigEmpty(), false); // disconnecting hasn't taken effect
- });
+ }, ref(so)));
+ // Bug 2302: 'so' needs to be bound to the handler;
+ // lambda capture won't work because closure would be destructed at .disconnect
so.emitSignal(sig);
BOOST_CHECK_EQUAL(hit, 1); // handler called