From 712ddafb749aada41daab85c36ac12f657b2307e Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Sat, 23 May 2020 15:29:17 +0200 Subject: [PATCH] Bundle: fix memory leak at init/reset --- resources/Bundle.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/resources/Bundle.java b/resources/Bundle.java index 84efceaf..fe3ac1a3 100644 --- a/resources/Bundle.java +++ b/resources/Bundle.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.Reader; @@ -1168,13 +1169,21 @@ public class Bundle> { boolean found = false; if (!resetToDefault && dir != null) { - // Look into Bundles.getDirectory() for .properties files try { + // Look into Bundles.getDirectory() for .properties files File file = getPropertyFile(dir, name.name(), locale); if (file != null) { - Reader reader = new InputStreamReader(new FileInputStream( - file), "UTF-8"); - resetMap(new PropertyResourceBundle(reader)); + InputStream in = new FileInputStream(file); + try { + Reader reader = new InputStreamReader(in, "UTF-8"); + try { + resetMap(new PropertyResourceBundle(reader)); + } finally { + reader.close(); + } + } finally { + in.close(); + } found = true; } } catch (IOException e) { -- 2.27.0