Details
-
Bug
-
Status: Closed
-
Critical
-
Resolution: Duplicate
-
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 "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)
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(); }}