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

                 Key: JAMES-1381
                 URL: https://issues.apache.org/jira/browse/JAMES-1381
             Project: JAMES Server
          Issue Type: Bug
          Components: NNTPServer & Repository (removed)
    Affects Versions: 2.3.2, 2.3.1, 2.3.0
            Reporter: Guangtai Liang
            Priority: Critical


The fix revision 108172 was aimed to remove resource leak bugs on the 
BufferedReader object "reader" (created in line 308), the InternetPrintWriter 
object "writer" in the method "handleConnection"of the file 
"/james/server/trunk/src/java/org/apache/james/nntpserver/NNTPHandler.java (now 
moved to 
/james/server/branches/v2.3/src/java/org/apache/james/nntpserver/NNTPHandler.java)"
 , but it is incomplete.

There are some problems: 
1. when "reader" isn't created successfully but the temp InputStreamReader 
object is created successfully (at line 308), the temp InputStreamReader object 
will be leaked. 
2. when "writer" isn't created successfully but the temp BufferedWriter object 
is created successfully (at line 309), the temp BufferedWriter object will be 
leaked. 
3. when the temp BufferedWriter object isn't created successfully but the temp 
OutputStreamWriter object is created successfully (at line 309), the temp 
OutputStreamWriter object 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 InputStreamReader 
object created at line 383 and the "outs" created at line 384 can be leaked). 
The buggy code is copied as bellows:

 public void handleConnection( Socket connection ) throws IOException {
        try {
            this.socket = connection;
            synchronized (this) {
                handlerThread = Thread.currentThread();
            }
            remoteIP = socket.getInetAddress().getHostAddress();
            remoteHost = socket.getInetAddress().getHostName();
            in = new BufferedInputStream(socket.getInputStream(), 1024);
            // An ASCII encoding can be used because all transmissions other
            // that those in the message body command are guaranteed
            // to be ASCII
 383           reader = new BufferedReader(new InputStreamReader(in, "ASCII"), 
512);
 384           outs = new BufferedOutputStream(socket.getOutputStream(), 1024);
 385           writer = new InternetPrintWriter(outs, true);
        } catch (Exception e) {
           ......
        }

        try {
          ......
        } catch (Exception e) {
           ......
        } finally {
 436         resetHandler();
        }
    }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to