Skip to content

Commit bc50b30

Browse files
committed
Restore fd leak protection
1 parent b0c8459 commit bc50b30

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

java/org/apache/catalina/startup/ContextConfig.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,24 +1694,44 @@ private WebXml getDefaultWebXmlFragment(WebXmlParser webXmlParser) {
16941694
long hostTimeStamp = 0;
16951695

16961696
if (globalWebXml != null) {
1697+
URLConnection uc = null;
16971698
try {
16981699
URI uri = new URI(globalWebXml.getSystemId());
16991700
URL url = uri.toURL();
1700-
URLConnection uc = url.openConnection();
1701+
uc = url.openConnection();
17011702
globalTimeStamp = uc.getLastModified();
17021703
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
17031704
globalTimeStamp = -1;
1705+
} finally {
1706+
if (uc != null) {
1707+
try {
1708+
uc.getInputStream().close();
1709+
} catch (IOException ioe) {
1710+
ExceptionUtils.handleThrowable(ioe);
1711+
globalTimeStamp = -1;
1712+
}
1713+
}
17041714
}
17051715
}
17061716

17071717
if (hostWebXml != null) {
1718+
URLConnection uc = null;
17081719
try {
17091720
URI uri = new URI(hostWebXml.getSystemId());
17101721
URL url = uri.toURL();
1711-
URLConnection uc = url.openConnection();
1722+
uc = url.openConnection();
17121723
hostTimeStamp = uc.getLastModified();
17131724
} catch (IOException | URISyntaxException | IllegalArgumentException e) {
17141725
hostTimeStamp = -1;
1726+
} finally {
1727+
if (uc != null) {
1728+
try {
1729+
uc.getInputStream().close();
1730+
} catch (IOException ioe) {
1731+
ExceptionUtils.handleThrowable(ioe);
1732+
hostTimeStamp = -1;
1733+
}
1734+
}
17151735
}
17161736
}
17171737

0 commit comments

Comments
 (0)