Bug 37407

Summary: file descriptor leak in jasper
Product: Tomcat 5 Reporter: fred
Component: JasperAssignee: Tomcat Developers Mailing List <dev>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P2    
Version: 5.5.12   
Target Milestone: ---   
Hardware: Other   
OS: Linux   

Description fred 2005-11-08 18:05:36 UTC
On my linux system I was in the proc directory for tomcat and noticed that
for each jsp file that was compiled I was ending up with two file
descriptors that were never closed.

I made the following change to JspReader and the problem seems to have gone
away.  I don't know what is causing the jsp files to be "reregistered"
multiple times that in turn causes the descriptor leak to appear.  Also I
am assuming there that err.jspError() always throws an Exception.  You could
also put the err.jspErrror() call inside the try/catch, but then you would have
to check for the type of exception in the catch block.

My impression is that it should never lead pushFile() with the reader still
open.

diff -C5 JspReader.java JspReader.java.new
*** JspReader.java      2005-09-23 09:45:24.000000000 -0400
--- JspReader.java.new  2005-11-08 12:04:14.000000000 -0500
***************
*** 513,522 ****
--- 513,527 ----
          String longName = file;
   
          int fileid = registerSourceFile(longName);
   
          if (fileid == -1) {
+             if (reader != null) {
+                 try {
+                     reader.close();
+                 } catch (Exception any) {}
+             }
              err.jspError("jsp.error.file.already.registered", file);
          }
   
          currFileId = fileid;
Comment 1 Yoav Shapira 2005-11-18 16:09:43 UTC
Makes sense to me: thanks for reporting this and investigating it.  Will apply.
Comment 2 Yoav Shapira 2005-11-18 16:36:21 UTC
Fixed.