From 1050ea9c70d1028b93f3d0784de1b30dd8444226 Mon Sep 17 00:00:00 2001
From: matthew_swift <matthew_swift@localhost>
Date: Wed, 06 May 2009 20:08:02 +0000
Subject: [PATCH] Fix issue 3962: Memory leaks after Bind <op> Unbind

---
 opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java |   47 +++++++++++++++++++++++++++++++++++++----------
 1 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
index 52bf912..8d68346 100644
--- a/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
+++ b/opends/src/server/org/opends/server/protocols/ldap/LDAPConnectionHandler.java
@@ -33,6 +33,8 @@
 import static org.opends.server.loggers.ErrorLogger.logError;
 import static org.opends.server.loggers.debug.DebugLogger.*;
 import org.opends.server.loggers.debug.DebugTracer;
+import org.opends.server.monitors.ClientConnectionMonitorProvider;
+
 import static org.opends.messages.ProtocolMessages.*;
 
 import static org.opends.server.util.ServerConstants.*;
@@ -187,6 +189,10 @@
   // The set of statistics collected for this connection handler.
   private LDAPStatistics statTracker;
 
+  // The client connection monitor provider associated with this
+  // connection handler.
+  private ClientConnectionMonitorProvider connMonitor;
+
   // The selector that will be used to multiplex connection acceptance
   // across multiple sockets by a single thread.
   private Selector selector;
@@ -301,15 +307,10 @@
     // * tcp reuse address
     // * num request handler
 
-    // Start/clear the stat tracker if LDAPv2 is being enabled.
+    // Clear the stat tracker if LDAPv2 is being enabled.
     if (currentConfig.isAllowLDAPV2() != config.isAllowLDAPV2()) {
       if (config.isAllowLDAPV2()) {
-        if (statTracker == null) {
-          statTracker = new LDAPStatistics(this,handlerName
-              + " Statistics");
-        } else {
-          statTracker.clearStatistics();
-        }
+        statTracker.clearStatistics();
       }
     }
 
@@ -358,11 +359,25 @@
    *          associated with the connection handler should also be
    *          closed.
    */
+  @Override
   public void finalizeConnectionHandler(Message finalizeReason,
       boolean closeConnections) {
     shutdownRequested = true;
     currentConfig.removeLDAPChangeListener(this);
 
+    if (connMonitor != null)
+    {
+      String lowerName =
+          toLowerCase(connMonitor.getMonitorInstanceName());
+      DirectoryServer.deregisterMonitorProvider(lowerName);
+    }
+
+    if (statTracker != null) {
+      String lowerName =
+        toLowerCase(statTracker.getMonitorInstanceName());
+      DirectoryServer.deregisterMonitorProvider(lowerName);
+    }
+
     DirectoryServer.deregisterSupportedLDAPVersion(2, this);
     DirectoryServer.deregisterSupportedLDAPVersion(3, this);
 
@@ -433,6 +448,7 @@
    * @return The set of active client connections that have been
    *         established through this connection handler.
    */
+  @Override
   public Collection<ClientConnection> getClientConnections() {
     LinkedList<ClientConnection> connectionList =
       new LinkedList<ClientConnection>();
@@ -452,6 +468,7 @@
    * @return The DN of the configuration entry with which this alert
    *         generator is associated.
    */
+  @Override
   public DN getComponentEntryDN() {
     return currentConfig.dn();
   }
@@ -461,6 +478,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public String getConnectionHandlerName() {
     return handlerName;
   }
@@ -498,6 +516,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public Collection<HostPort> getListeners() {
     return listeners;
   }
@@ -547,6 +566,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public String getProtocol() {
     return protocol;
   }
@@ -595,6 +615,7 @@
   /**
    * {@inheritDoc}
    */
+  @Override
   public void initializeConnectionHandler(LDAPConnectionHandlerCfg config)
          throws ConfigException, InitializationException
   {
@@ -648,9 +669,6 @@
     nameBuffer.append(listenPort);
     handlerName = nameBuffer.toString();
 
-    // Perform any additional initialization that might be required.
-    statTracker = new LDAPStatistics(this, handlerName + " Statistics");
-
     // Attempt to bind to the listen port on all configured addresses to
     // verify whether the connection handler will be able to start.
     for (InetAddress a : listenAddresses) {
@@ -693,6 +711,13 @@
       DirectoryServer.registerSupportedLDAPVersion(2, this);
     }
 
+    // Create and register monitors.
+    statTracker = new LDAPStatistics(handlerName + " Statistics");
+    DirectoryServer.registerMonitorProvider(statTracker);
+
+    connMonitor = new ClientConnectionMonitorProvider(this);
+    DirectoryServer.registerMonitorProvider(connMonitor);
+
     // Register this as a change listener.
     config.addLDAPChangeListener(this);
   }
@@ -812,6 +837,7 @@
    * Operates in a loop, accepting new connections and ensuring that
    * requests on those connections are handled properly.
    */
+  @Override
   public void run() {
     setName(handlerName);
     boolean listening = false;
@@ -1124,6 +1150,7 @@
    * @param buffer
    *          The buffer to which the information should be appended.
    */
+  @Override
   public void toString(StringBuilder buffer) {
     buffer.append(handlerName);
   }

--
Gitblit v1.10.0