Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Won't Fix
-
2.3.0, 2.3.1, 2.3.2
-
None
Description
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)
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(); }}