Author: markt
Date: Thu Feb 18 12:26:50 2016
New Revision: 1731055
URL: http://svn.apache.org/viewvc?rev=1731055&view=rev
Log:
Fix some resource leaks in the error handling for accessing files from JARs and
WARs.
Modified:
tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java?rev=1731055&r1=1731054&r2=1731055&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarResource.java Thu Feb
18 12:26:50 2016
@@ -39,8 +39,9 @@ public class JarResource extends Abstrac
@Override
protected JarInputStreamWrapper getJarInputStreamWrapper() {
+ JarFile jarFile = null;
try {
- JarFile jarFile = getArchiveResourceSet().openJarFile();
+ jarFile = getArchiveResourceSet().openJarFile();
// Need to create a new JarEntry so the certificates can be read
JarEntry jarEntry = jarFile.getJarEntry(getResource().getName());
InputStream is = jarFile.getInputStream(jarEntry);
@@ -50,6 +51,9 @@ public class JarResource extends Abstrac
log.debug(sm.getString("jarResource.getInputStreamFail",
getResource().getName(), getBaseUrl()), e);
}
+ if (jarFile != null) {
+ getArchiveResourceSet().closeJarFile();
+ }
return null;
}
}
Modified: tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java?rev=1731055&r1=1731054&r2=1731055&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/webresources/JarWarResource.java Thu
Feb 18 12:26:50 2016
@@ -44,29 +44,22 @@ public class JarWarResource extends Abst
@Override
protected JarInputStreamWrapper getJarInputStreamWrapper() {
+ JarFile warFile = null;
+ JarInputStream jarIs = null;
+ JarEntry entry = null;
try {
- JarFile warFile = getArchiveResourceSet().openJarFile();
+ warFile = getArchiveResourceSet().openJarFile();
JarEntry jarFileInWar = warFile.getJarEntry(archivePath);
InputStream isInWar = warFile.getInputStream(jarFileInWar);
- JarInputStream jarIs = new JarInputStream(isInWar);
- JarEntry entry = jarIs.getNextJarEntry();
+ jarIs = new JarInputStream(isInWar);
+ entry = jarIs.getNextJarEntry();
while (entry != null &&
!entry.getName().equals(getResource().getName())) {
entry = jarIs.getNextJarEntry();
}
if (entry == null) {
- try {
- jarIs.close();
- } catch (IOException ioe) {
- // Ignore
- }
- try {
- warFile.close();
- } catch (IOException ioe) {
- // Ignore
- }
return null;
}
@@ -77,6 +70,19 @@ public class JarWarResource extends Abst
getResource().getName(), getBaseUrl()), e);
}
return null;
+ } finally {
+ if (entry == null) {
+ if (jarIs != null) {
+ try {
+ jarIs.close();
+ } catch (IOException ioe) {
+ // Ignore
+ }
+ }
+ if (warFile != null) {
+ getArchiveResourceSet().closeJarFile();
+ }
+ }
}
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL:
http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1731055&r1=1731054&r2=1731055&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Thu Feb 18 12:26:50 2016
@@ -84,6 +84,10 @@
Refactor the web application class loader to reduce the impact of JAR
scanning on the memory footprint of the web application. (markt)
</fix>
+ <fix>
+ Fix some resource leaks in the error handling for accessing files from
+ JARs and WARs. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]