From: Thomas Jarosch Date: Wed, 11 Feb 2015 16:55:28 +0000 (+0100) Subject: Check weak_ptr before using it X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4aad91a48f2831ac81d6d6aa52d43a4300aacc33;p=pingcheck Check weak_ptr before using it --- diff --git a/src/icmp/icmppinger.cpp b/src/icmp/icmppinger.cpp index f8b95fd..d5c2b50 100644 --- a/src/icmp/icmppinger.cpp +++ b/src/icmp/icmppinger.cpp @@ -149,12 +149,21 @@ void IcmpPinger::stop_pinging() << DestinationEndpoint.address().to_string() << ": cancel timer" << endl; IcmpPacketReceiveTimer.cancel(); - IcmpPingerItem icmp_item = boost::static_pointer_cast( get_myself().lock() ); GlobalLogger.debug() << DestinationEndpoint.address().to_string() << ": unregister" << endl; - PacketDistributor->unregister_pinger( icmp_item ); + + IcmpPingerItem icmp_item = boost::static_pointer_cast( 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; + } }