id summary reporter owner description type status milestone component version severity resolution keywords cc 7015 boost::signals::connection with shared_ptr to connected signal Nick Mayer Douglas Gregor "If you create a connection with a shared_ptr that controls the lifespan of the signal an access violation occurs on disconnection if that is the last remaining reference to the object. {{{ #!c++ class Child : public boost::signals::trackable { public: Child(){} virtual ~Child(){} void callback( int a, int b ) { printf( ""Child::callback( %d, %d )\n"", a, b ); } boost::signal mSignal; }; int main(int argc, char* argv[]) { boost::shared_ptr c( new Child ); boost::signals::connection con; con = c->mSignal.connect( boost::bind( &Child::callback, c, 1, _1 ) ); c->mSignal( 5 ); c.reset(); // The connection is the only thing keeping it alive. When we disconnect // it will also destroy the signal. This causes a memory access violation // when the signal containing the list of connections gets deleted while // removing an item from that list. con.disconnect(); } }}} The fix is to prevent the slot from going out of scope during the act of disconnecting from the signal. {{{ diff --git a/libs/signals/src/signal_base.cpp b/libs/signals/src/signal_base.cpp index 759672d..918e811 100644 --- a/libs/signals/src/signal_base.cpp +++ b/libs/signals/src/signal_base.cpp @@ -143,8 +143,14 @@ namespace boost { self->flags.delayed_disconnect = true; } else { // Just remove the slot now, it's safe + // There is a chance that the binding has the last reference to + // the signal, and destroying it will destroy the signal. To prevent + // this from causing a problem keep a local copy of the binding + // during it's removal from the slot list. + boost::any keep_alive = (*slot)->second; self->slots_.erase(*slot); + return; } } } }}}" Bugs new To Be Determined signals Boost 1.49.0 Problem signals connection shared_ptr