Undoing commit e58d750735048b76721ade950d3b9e0c75d201f7.
authorGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 5 Mar 2012 11:40:19 +0000 (08:40 -0300)
committerGuilherme Maciel Ferreira <guilherme.maciel.ferreira@gmail.com>
Mon, 5 Mar 2012 11:40:41 +0000 (08:40 -0300)
- 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
src/host/pingerfactory.h
src/host/pingrotate.cpp
src/host/pingrotate.h
src/host/pingscheduler.cpp
src/icmp/icmppinger.cpp
src/icmp/icmppinger.h
src/tcp/tcppinger.cpp
src/tcp/tcppinger.h

index 60a412d..561d170 100644 (file)
@@ -66,7 +66,7 @@ PingerFactory::~PingerFactory()
  */
 PingerItem PingerFactory::createPinger(
         const PingProtocol protocol,
-        const shared_ptr<io_service> 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_service> io_serv,
+        io_service &io_serv,
         const string &network_interface,
         const string &destination_address,
         const uint16_t destination_port,
index 3a9e9e1..05d3415 100644 (file)
@@ -39,13 +39,13 @@ class PingerFactory
 public:
     static PingerItem createPinger(
             const PingProtocol protocol,
-            const boost::shared_ptr<boost::asio::io_service> io_serv,
+            boost::asio::io_service &io_serv,
             const std::string &network_interface
     );
 
     static PingRotateItem createPinger(
             const PingProtocolList &protocol_list,
-            const boost::shared_ptr<boost::asio::io_service> io_serv,
+            boost::asio::io_service &io_serv,
             const std::string &network_interface,
             const std::string &destination_address,
             const uint16_t destination_port,
index 4d11fde..c8b3433 100644 (file)
@@ -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_service> io_serv,
+        io_service &io_serv,
         const string &network_interface,
         const string &destination_address,
         const uint16_t destination_port,
index ab49f59..f666d11 100644 (file)
@@ -46,7 +46,7 @@ class PingRotate
 {
 public:
     PingRotate(
-            const boost::shared_ptr<boost::asio::io_service> 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<boost::asio::io_service> IoService;
+    boost::asio::io_service &IoService;
     /// The network interface name
     std::string NetworkInterfaceName;
     /// The list of IPs which are aliases to the host DNS
index 3b5dcaf..6138afa 100644 (file)
@@ -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_service> io_serv( &IoService );
-
     Ping = PingerFactory::createPinger(
             ping_protocol_list,
-            io_serv,
+            IoService,
             network_interface,
             destination_address,
             destination_port,
index 2493afe..062098e 100644 (file)
@@ -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_service> 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() ),
index 80033e4..f92b33b 100644 (file)
@@ -13,7 +13,6 @@
 
 #include <boost/asio.hpp>
 #include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
 
 #include "host/networkinterface.hpp"
 #include "host/pinger.h"
@@ -32,7 +31,7 @@ class IcmpPinger : public Pinger
 {
 public:
     IcmpPinger(
-            const boost::shared_ptr<boost::asio::io_service> 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<boost::asio::io_service> IoService;
+    boost::asio::io_service &IoService;
     /// The destination host
     boost::asio::ip::icmp::endpoint DestinationEndpoint;
     /// Network layer protocol used to ping, IPv4 or IPv6
index c0da7ef..5ed53d6 100644 (file)
@@ -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_service> 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() ),
index 127857c..914322c 100644 (file)
@@ -27,7 +27,6 @@ on this file might be covered by the GNU General Public License.
 #include <boost/asio.hpp>
 #include <boost/asio/ip/tcp_raw_protocol.hpp>
 #include <boost/function.hpp>
-#include <boost/shared_ptr.hpp>
 
 #include "host/networkinterface.hpp"
 #include "host/pinger.h"
@@ -46,7 +45,7 @@ class TcpPinger : public Pinger
 {
 public:
     TcpPinger(
-            const boost::shared_ptr<boost::asio::io_service> 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<boost::asio::io_service> 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