Bug 52742 - An incomplete fix for the resource leak bug in Replace.java
An incomplete fix for the resource leak bug in Replace.java
Status: RESOLVED FIXED
Product: Ant
Classification: Unclassified
Component: Core
1.8.2
All All
: P2 minor (vote)
: 1.9.0
Assigned To: Ant Notifications List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-02-23 07:45 UTC by lianggt08
Modified: 2012-02-27 22:17 UTC (History)
1 user (show)



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lianggt08 2012-02-23 07:45:37 UTC
The fix revision 269961 was aimed to remove resource leak bugs on the InputStreamReader object "reader" (created in line 314), the OutputStreamWriter object (line 316) in the method "processFile"of the file "/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Replace.java" , but 
it is incomplete.

There are some problems: 
1. when "reader" isn't created successfully but the temp FileInputStream object is created successfully (at line 315), the temp FileInputStream object will be leaked. 
2. when "writer" isn't created successfully but the temp FileOutputStream object is created successfully (at line 316), the temp FileOutputStream object will be leaked. 
3. when the statements at lines 327-367 throw some exception, "bw" will be leaked;
4. when the statements at lines 327-367 throw some exception, "br" 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.
Comment 1 Jesse Glick 2012-02-27 22:17:01 UTC
Committed revision 1294360.