Author: violetagg
Date: Thu Jul 9 08:08:24 2015
New Revision: 1690011
URL: http://svn.apache.org/r1690011
Log:
Fix possible resource leaks by closing streams properly. Issues reported by
Coverity Scan.
Modified:
tomcat/trunk/java/org/apache/catalina/ant/ValidatorTask.java
tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
Modified: tomcat/trunk/java/org/apache/catalina/ant/ValidatorTask.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ant/ValidatorTask.java?rev=1690011&r1=1690010&r2=1690011&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ant/ValidatorTask.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ant/ValidatorTask.java Thu Jul 9
08:08:24 2015
@@ -93,12 +93,8 @@ public class ValidatorTask extends BaseR
// SecurityManager assume that untrusted applications may be deployed.
Digester digester = DigesterFactory.newDigester(
true, true, null, Globals.IS_SECURITY_ENABLED);
- try {
- file = file.getCanonicalFile();
- InputStream stream =
- new BufferedInputStream(new FileInputStream(file));
- InputSource is =
- new InputSource(file.toURI().toURL().toExternalForm());
+ try (InputStream stream = new BufferedInputStream(new
FileInputStream(file.getCanonicalFile()));) {
+ InputSource is = new
InputSource(file.toURI().toURL().toExternalForm());
is.setByteStream(stream);
digester.parse(is);
handleOutput("web.xml validated");
Modified: tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java?rev=1690011&r1=1690010&r2=1690011&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java Thu
Jul 9 08:08:24 2015
@@ -731,9 +731,14 @@ public class FarmWarDeployer extends Clu
return false;
}
}
- java.io.FileInputStream is = new java.io.FileInputStream(from);
- java.io.FileOutputStream os = new java.io.FileOutputStream(to,
- false);
+ } catch (IOException e) {
+ log.error(sm.getString("farmWarDeployer.fileCopyFail",
+ from, to), e);
+ return false;
+ }
+
+ try (java.io.FileInputStream is = new java.io.FileInputStream(from);
+ java.io.FileOutputStream os = new java.io.FileOutputStream(to,
false);) {
byte[] buf = new byte[4096];
while (true) {
int len = is.read(buf);
@@ -741,8 +746,6 @@ public class FarmWarDeployer extends Clu
break;
os.write(buf, 0, len);
}
- is.close();
- os.close();
} catch (IOException e) {
log.error(sm.getString("farmWarDeployer.fileCopyFail",
from, to), e);
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]