Bug 52724 - An incomplete fix for the resource leak bugs in Catalina.java
An incomplete fix for the resource leak bugs in Catalina.java
Status: RESOLVED FIXED
Product: Tomcat 7
Classification: Unclassified
Component: Catalina
trunk
PC All
: P2 enhancement (vote)
: ---
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2012-02-21 10:35 UTC by lianggt08
Modified: 2012-03-05 20:12 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description lianggt08 2012-02-21 10:35:32 UTC
The fix revision 730178 was aimed to remove an resource leak bug on the  FileInputStream object "fis" (created line 458), the Socket "socket" (created at line 477), 

the OutputStream object "stream", and the FileInputStream object "inputStream" in the file "/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/Catalina.java" , but 

it is incomplete. 

There are some problems: 
1. the InputSource object "is" created at line 452 is not closed. 
2. when the statements at lines 455-457 throw some exception, the "fis" can not be closed as expected. 
3. when the statements at lines 480-483 throw some exception, the "socket" and the "stream" can not be closed as expected. 
4. when the statements at lines 574-576 throw some exception, the "inputStream" can not be closed as expected. 

The best way to close such resource objects is putting such close operations in the finaly block of a try-catch-finally structure.
Comment 1 Mark Thomas 2012-03-05 20:12:51 UTC
(In reply to comment #0)
For all of the cases raised (at least those that are valid) the JVM is about 10 lines away from shutting down which makes any possible resource leak pretty much irrelevant. This demonstrates the necessity of understanding the code before claiming that a critical bug exists.

I was tempted to resolve this bug as INVALID but it is true that the code could be cleaner and that would prevent someone creating a duplicate (and similarly pointless) issue in the future.

I have therefore changed this bug to an enhancement and cleaned up the code.

Responding to the specific points:

> 1. the InputSource object "is" created at line 452 is not closed. 

It is an InputSource not an InputStream. There is no close() method.

> 2. when the statements at lines 455-457 throw some exception, the "fis" can not
> be closed as expected.

And less than a second later the JVM shuts down. Not an issue. Cleaned up anyway.
 
> 3. when the statements at lines 480-483 throw some exception, the "socket" and
> the "stream" can not be closed as expected.

Non-issue for the same reason as 2.
 
> 4. when the statements at lines 574-576 throw some exception, the "inputStream"
> can not be closed as expected.

Non-issue for the same reason as 2.

Before raising a bug, especially a critical one, it is important to do sufficient research to be very sure of your ground. If someone can't be bothered to do the research to ensure a bug is valid, don't expect the Tomcat committers to bother to explain why they have closed a bug as INVALID.