Check weak_ptr before using it
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 11 Feb 2015 16:55:28 +0000 (17:55 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 11 Feb 2015 16:55:28 +0000 (17:55 +0100)
src/icmp/icmppinger.cpp

index f8b95fd..d5c2b50 100644 (file)
@@ -149,12 +149,21 @@ void IcmpPinger::stop_pinging()
            << DestinationEndpoint.address().to_string()
            << ": cancel timer" << endl;
     IcmpPacketReceiveTimer.cancel();
-    IcmpPingerItem icmp_item = boost::static_pointer_cast<IcmpPinger>( get_myself().lock() );
 
     GlobalLogger.debug()
            << DestinationEndpoint.address().to_string()
            << ": unregister" << endl;
-    PacketDistributor->unregister_pinger( icmp_item );
+
+    IcmpPingerItem icmp_item = boost::static_pointer_cast<IcmpPinger>( get_myself().lock() );
+    if ( icmp_item )
+    {
+        PacketDistributor->unregister_pinger( icmp_item );
+    } else
+    {
+        GlobalLogger.warning()
+            << DestinationEndpoint.address().to_string()
+            << ": weak pointer to pinger broken is empty. Huh?" << endl;
+    }
 }