An incomplete fix for the resource leak bugs in RemoteManagerHandler.java
-------------------------------------------------------------------------
Key: JAMES-1383
URL: https://issues.apache.org/jira/browse/JAMES-1383
Project: JAMES Server
Issue Type: Bug
Components: Remote Manager
Affects Versions: 2.3.2, 2.3.1, 2.3.0
Reporter: Guangtai Liang
Priority: Critical
The fix revision 107701 was aimed to remove resource leak bugs on the
BufferedReader object "in" (created in line 227), the PrintWriter object "out "
in the method "handleConnection"of the file
"/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
(now moved to
/james/server/branches/v2.3/src/java/org/apache/james/remotemanager/RemoteManagerHandler.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 227), the temp InputStreamReader object will
be leaked.
2. when "out" isn't created successfully but the temp BufferedWriter object is
created successfully (at line 228), 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 228), 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 257 and the temp BufferedWriter object and the temp
OutputStreamWriter object created at line 258 can be leaked). The buggy code is
copied as bellows:
public void handleConnection( final Socket connection )
throws IOException {
socket = connection;
String remoteIP = socket.getInetAddress().getHostAddress();
String remoteHost = socket.getInetAddress().getHostName();
synchronized (this) {
handlerThread = Thread.currentThread();
}
try {
257 in = new BufferedReader(new
InputStreamReader(socket.getInputStream(), "ASCII"),
512);
258 out = new PrintWriter(new BufferedWriter(new OutputStreamWriter
(socket.getOutputStream()), 512), false);
......
} catch ( final IOException e ) {
......
} finally {
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]