Uploaded image for project: 'James Server'
  1. James Server
  2. JAMES-1382

An incomplete fix for the resource leak bugs in NNTPHandler.java

    XMLWordPrintableJSON

Details

    Description

      The fix revision 108172 was aimed to remove resource leak bugs on the BufferedReader object "in" (created in line 192), the Socket object "this.socket", the OutputStream object "outs", and the InternetPrintWriter object "out" in the method "handleConnection"of the file "/james/server/trunk/src/java/org/apache/james/pop3server/POP3Handler.java (now moved to /james/server/branches/v2.3/src/java/org/apache/james/pop3server/POP3Handler.java)" , but it is incomplete.

      There are some problems:
      1. when "in" isn't created successfully but the temp InputStreamReader object is created successfully (at line 193), the temp InputStreamReader object will be leaked.
      2. when the statements at lines 189-197 throw some exception, "this.socket" and "in" will be leaked.

      The best way to close such resource objects is putting such close operations for all resource objects in the finaly block of a try-catch-finally structure and then putting all other code in a try block.

      The problem still exists in the head revision (the temp BufferedInputStream object created at line 233 and the "in" created at line 233 can be leaked). The buggy code is copied as bellows:

      /**

      • @see org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection

      (Socket)
      */
      public void handleConnection( Socket connection )
      throws IOException {

      String remoteHost = "";
      String remoteIP = "";

      try {
      this.socket = connection;
      synchronized (this)

      { handlerThread = Thread.currentThread(); }

      232 // in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"),

      512);
      233 in = new CRLFTerminatedReader(new BufferedInputStream(socket.getInputStream(), 512),

      "ASCII");
      234 remoteIP = socket.getInetAddress().getHostAddress ();
      235 remoteHost = socket.getInetAddress().getHostName ();
      } catch (Exception e)

      { ...... }

      250 if (getLogger().isInfoEnabled())

      { StringBuffer logBuffer = new StringBuffer(128) .append("Connection from ") .append(remoteHost) .append(" (") .append(remoteIP) .append(") "); 258 getLogger().info(logBuffer.toString()); }

      try

      { ...... }

      catch (Exception e)

      { ...... }

      finally

      { resetHandler(); }

      }

      Attachments

        Activity

          People

            Unassigned Unassigned
            guangtai Guangtai Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 10m
                10m
                Remaining:
                Remaining Estimate - 10m
                10m
                Logged:
                Time Spent - Not Specified
                Not Specified