Browse Source

[master] Fixed memory leak in IfaceMgr singleton.

Marcin Siodelski 12 years ago
parent
commit
3e963e68d9
2 changed files with 2 additions and 25 deletions
  1. 2 18
      src/lib/dhcp/iface_mgr.cc
  2. 0 7
      src/lib/dhcp/iface_mgr.h

+ 2 - 18
src/lib/dhcp/iface_mgr.cc

@@ -36,26 +36,10 @@ using namespace isc::util::io::internal;
 namespace isc {
 namespace dhcp {
 
-/// IfaceMgr is a singleton implementation
-IfaceMgr* IfaceMgr::instance_ = 0;
-
-void
-IfaceMgr::instanceCreate() {
-    if (instance_) {
-        // no need to do anything. Instance is already created.
-        // Who called it again anyway? Uh oh. Had to be us, as
-        // this is private method.
-        return;
-    }
-    instance_ = new IfaceMgr();
-}
-
 IfaceMgr&
 IfaceMgr::instance() {
-    if (instance_ == 0) {
-        instanceCreate();
-    }
-    return (*instance_);
+    static IfaceMgr iface_mgr;
+    return (iface_mgr);
 }
 
 IfaceMgr::Iface::Iface(const std::string& name, int ifindex)

+ 0 - 7
src/lib/dhcp/iface_mgr.h

@@ -537,9 +537,6 @@ protected:
     /// List of available interfaces
     IfaceCollection ifaces_;
 
-    /// a pointer to a sole instance of this class (a singleton)
-    static IfaceMgr * instance_;
-
     // TODO: Also keep this interface on Iface once interface detection
     // is implemented. We may need it e.g. to close all sockets on
     // specific interface
@@ -580,10 +577,6 @@ protected:
     SessionCallback session_callback_;
 private:
 
-    /// @brief Creates a single instance of this class (a singleton implementation)
-    static void
-    instanceCreate();
-
     /// @brief Joins IPv6 multicast group on a socket.
     ///
     /// Socket must be created and bound to an address. Note that this