From ff10c263327890c8bb4a85dcbe1a261ae2bcee0b Mon Sep 17 00:00:00 2001 From: lujiefsi Date: Mon, 10 Jan 2022 03:56:22 -0600 Subject: [PATCH] fix resource leak (#7361) Fix resource leaks --- .../java/org/eclipse/jetty/security/PropertyUserStore.java | 6 +++++- .../src/main/java/org/eclipse/jetty/start/Modules.java | 5 ++++- .../main/java/org/eclipse/jetty/xml/XmlConfiguration.java | 7 ++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java index cac77732ba2..cdf01eac4b4 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/PropertyUserStore.java @@ -16,6 +16,7 @@ package org.eclipse.jetty.security; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -218,7 +219,10 @@ public class PropertyUserStore extends UserStore implements PathWatcher.Listener throw new IllegalStateException("Config does not exist: " + config); Properties properties = new Properties(); - properties.load(config.getInputStream()); + try (InputStream inputStream = config.getInputStream()) + { + properties.load(inputStream); + } Set known = new HashSet<>(); diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java index 65007cc2c00..a6e269109d3 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java @@ -70,7 +70,10 @@ public class Modules implements Iterable Path deprecatedPath = _baseHome.getPath("modules/deprecated.properties"); if (deprecatedPath != null && FS.exists(deprecatedPath)) { - _deprecated.load(new FileInputStream(deprecatedPath.toFile())); + try (FileInputStream inputStream = new FileInputStream(deprecatedPath.toFile())) + { + _deprecated.load(inputStream); + } } } catch (IOException e) diff --git a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java index 4cd59c3a879..a102b27df17 100644 --- a/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java +++ b/jetty-xml/src/main/java/org/eclipse/jetty/xml/XmlConfiguration.java @@ -1823,7 +1823,12 @@ public class XmlConfiguration properties.put(arg.substring(0, i), arg.substring(i + 1)); } else if (arg.toLowerCase(Locale.ENGLISH).endsWith(".properties")) - properties.load(Resource.newResource(arg).getInputStream()); + { + try (InputStream inputStream = Resource.newResource(arg).getInputStream()) + { + properties.load(inputStream); + } + } } // For all arguments, parse XMLs