From 1b42e23c44199ca3a5f851e856158ddf0949a751 Mon Sep 17 00:00:00 2001 From: lujiefsi Date: Fri, 7 Jan 2022 16:25:38 +0800 Subject: [PATCH 1/2] fix resource leak --- .../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 cac77732ba28..cdf01eac4b4d 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 @@ 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 @@ protected void loadUsers() throws IOException 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 65007cc2c00b..85505c0b1008 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 Modules(BaseHome basehome, StartArgs args) 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 4cd59c3a8795..a102b27df175 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 static void main(final String... args) throws Exception 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 From c436a93a4b88747ca66d933ddf6da0dedaa3698b Mon Sep 17 00:00:00 2001 From: lujiefsi Date: Fri, 7 Jan 2022 18:47:00 +0800 Subject: [PATCH 2/2] fix style error --- jetty-start/src/main/java/org/eclipse/jetty/start/Modules.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 85505c0b1008..a6e269109d30 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 @@ -72,7 +72,7 @@ public Modules(BaseHome basehome, StartArgs args) { try (FileInputStream inputStream = new FileInputStream(deprecatedPath.toFile())) { - _deprecated.load(inputStream); + _deprecated.load(inputStream); } } }