From d4c54924cb970c4a6807b93347e21645542c4ee9 Mon Sep 17 00:00:00 2001 From: Guilherme Maciel Ferreira Date: Mon, 5 Mar 2012 08:40:19 -0300 Subject: [PATCH] Undoing commit e58d750735048b76721ade950d3b9e0c75d201f7. - Using the io_service reference instead of the shared_ptr, because it caused a double freed error, because it was a stack object in the PingScheduler (boost::asio::io_service IoService) and a smart pointer elsewhere, thus, the smart pointers were releasing the stack memory. And once the PingScheduler didn't had a counter by itself, the program was dumping in the PingScheduler destructor. Once the Boost.Asio library uses the reference itself (e.g. basic_raw_socket(boost::asio::io_service& io_service, )), I decided to keep like it was before. --- src/host/pingerfactory.cpp | 4 ++-- src/host/pingerfactory.h | 4 ++-- src/host/pingrotate.cpp | 2 +- src/host/pingrotate.h | 4 ++-- src/host/pingscheduler.cpp | 4 +--- src/icmp/icmppinger.cpp | 6 +++--- src/icmp/icmppinger.h | 5 ++--- src/tcp/tcppinger.cpp | 6 +++--- src/tcp/tcppinger.h | 5 ++--- 9 files changed, 18 insertions(+), 22 deletions(-) diff --git a/src/host/pingerfactory.cpp b/src/host/pingerfactory.cpp index 60a412d..561d170 100644 --- a/src/host/pingerfactory.cpp +++ b/src/host/pingerfactory.cpp @@ -66,7 +66,7 @@ PingerFactory::~PingerFactory() */ PingerItem PingerFactory::createPinger( const PingProtocol protocol, - const shared_ptr io_serv, + io_service &io_serv, const string &network_interface ) { @@ -127,7 +127,7 @@ PingerItem PingerFactory::createPinger( */ PingRotateItem PingerFactory::createPinger( const PingProtocolList &protocol_list, - const shared_ptr io_serv, + io_service &io_serv, const string &network_interface, const string &destination_address, const uint16_t destination_port, diff --git a/src/host/pingerfactory.h b/src/host/pingerfactory.h index 3a9e9e1..05d3415 100644 --- a/src/host/pingerfactory.h +++ b/src/host/pingerfactory.h @@ -39,13 +39,13 @@ class PingerFactory public: static PingerItem createPinger( const PingProtocol protocol, - const boost::shared_ptr io_serv, + boost::asio::io_service &io_serv, const std::string &network_interface ); static PingRotateItem createPinger( const PingProtocolList &protocol_list, - const boost::shared_ptr io_serv, + boost::asio::io_service &io_serv, const std::string &network_interface, const std::string &destination_address, const uint16_t destination_port, diff --git a/src/host/pingrotate.cpp b/src/host/pingrotate.cpp index 4d11fde..c8b3433 100644 --- a/src/host/pingrotate.cpp +++ b/src/host/pingrotate.cpp @@ -48,7 +48,7 @@ using boost::shared_ptr; * host. The protocols will be used in the order they are in the list. */ PingRotate::PingRotate( - const shared_ptr io_serv, + io_service &io_serv, const string &network_interface, const string &destination_address, const uint16_t destination_port, diff --git a/src/host/pingrotate.h b/src/host/pingrotate.h index ab49f59..f666d11 100644 --- a/src/host/pingrotate.h +++ b/src/host/pingrotate.h @@ -46,7 +46,7 @@ class PingRotate { public: PingRotate( - const boost::shared_ptr io_serv, + boost::asio::io_service &io_serv, const std::string &network_interface, const std::string &destination_address, const uint16_t destination_port, @@ -80,7 +80,7 @@ private: // /// The IO service object, which has the loop event - boost::shared_ptr IoService; + boost::asio::io_service &IoService; /// The network interface name std::string NetworkInterfaceName; /// The list of IPs which are aliases to the host DNS diff --git a/src/host/pingscheduler.cpp b/src/host/pingscheduler.cpp index 3b5dcaf..6138afa 100644 --- a/src/host/pingscheduler.cpp +++ b/src/host/pingscheduler.cpp @@ -85,11 +85,9 @@ PingScheduler::PingScheduler( BOOST_ASSERT( (0 <= ping_fail_percentage_limit) && (ping_fail_percentage_limit <= 100) ); BOOST_ASSERT( !nameserver.empty() ); - shared_ptr io_serv( &IoService ); - Ping = PingerFactory::createPinger( ping_protocol_list, - io_serv, + IoService, network_interface, destination_address, destination_port, diff --git a/src/icmp/icmppinger.cpp b/src/icmp/icmppinger.cpp index 2493afe..062098e 100644 --- a/src/icmp/icmppinger.cpp +++ b/src/icmp/icmppinger.cpp @@ -48,7 +48,7 @@ using I2n::Logger::GlobalLogger; * @param echo_reply_timeout_in_sec The amount of time to wait for a reply. */ IcmpPinger::IcmpPinger( - const shared_ptr io_serv, + io_service &io_serv, const icmp::socket::protocol_type &protocol, const string &source_network_interface, const int echo_reply_timeout_in_sec @@ -56,9 +56,9 @@ IcmpPinger::IcmpPinger( IoService( io_serv ), DestinationEndpoint(), Protocol( protocol ), - Socket( *IoService, Protocol ), + Socket( IoService, Protocol ), NetInterface( source_network_interface, Socket ), - IcmpPacketReceiveTimer( *IoService ), + IcmpPacketReceiveTimer( IoService ), Identifier( 0 ), SequenceNumber( 0 ), TimeSent( microsec_clock::universal_time() ), diff --git a/src/icmp/icmppinger.h b/src/icmp/icmppinger.h index 80033e4..f92b33b 100644 --- a/src/icmp/icmppinger.h +++ b/src/icmp/icmppinger.h @@ -13,7 +13,6 @@ #include #include -#include #include "host/networkinterface.hpp" #include "host/pinger.h" @@ -32,7 +31,7 @@ class IcmpPinger : public Pinger { public: IcmpPinger( - const boost::shared_ptr io_serv, + boost::asio::io_service &io_serv, const boost::asio::ip::icmp::socket::protocol_type &protocol, const std::string &source_network_interface, const int echo_reply_timeout_in_sec @@ -60,7 +59,7 @@ private: private: /// The IO service object, which has the loop event - boost::shared_ptr IoService; + boost::asio::io_service &IoService; /// The destination host boost::asio::ip::icmp::endpoint DestinationEndpoint; /// Network layer protocol used to ping, IPv4 or IPv6 diff --git a/src/tcp/tcppinger.cpp b/src/tcp/tcppinger.cpp index c0da7ef..5ed53d6 100644 --- a/src/tcp/tcppinger.cpp +++ b/src/tcp/tcppinger.cpp @@ -66,7 +66,7 @@ using I2n::Logger::GlobalLogger; * @param echo_reply_timeout_in_sec The amount of time to wait for a reply. */ TcpPinger::TcpPinger( - const shared_ptr io_serv, + io_service &io_serv, const tcp_raw_protocol::socket::protocol_type &protocol, const string &source_network_interface_name, const int rst_reply_timeout_in_sec @@ -74,9 +74,9 @@ TcpPinger::TcpPinger( IoService( io_serv ), DestinationEndpoint(), Protocol( protocol ), - Socket( *IoService, Protocol ), + Socket( IoService, Protocol ), NetInterface( source_network_interface_name, Socket ), - TcpSegmentReceiveTimer( *IoService ), + TcpSegmentReceiveTimer( IoService ), Identifier( 0 ), SequenceNumber( 0 ), TimeSent( microsec_clock::universal_time() ), diff --git a/src/tcp/tcppinger.h b/src/tcp/tcppinger.h index 127857c..914322c 100644 --- a/src/tcp/tcppinger.h +++ b/src/tcp/tcppinger.h @@ -27,7 +27,6 @@ on this file might be covered by the GNU General Public License. #include #include #include -#include #include "host/networkinterface.hpp" #include "host/pinger.h" @@ -46,7 +45,7 @@ class TcpPinger : public Pinger { public: TcpPinger( - const boost::shared_ptr io_serv, + boost::asio::io_service &io_serv, const boost::asio::ip::tcp_raw_protocol::socket::protocol_type &protocol, const std::string &source_network_interface_name, const int rst_reply_timeout_in_sec @@ -83,7 +82,7 @@ private: private: /// IO service object, which has the loop event - boost::shared_ptr IoService; + boost::asio::io_service &IoService; /// The destination host boost::asio::ip::tcp_raw_protocol::endpoint DestinationEndpoint; /// Network layer protocol used to ping, IPv4 or IPv6 -- 1.7.1