From: Niki Roo Date: Sat, 23 May 2020 13:29:17 +0000 (+0200) Subject: Bundle: fix memory leak at init/reset X-Git-Url: https://git.nikiroo.be/?a=commitdiff_plain;h=59e9bd1e353b9d01cee7da6055ebd36d8d045d3a;p=fanfix.git Bundle: fix memory leak at init/reset --- diff --git a/src/be/nikiroo/utils/resources/Bundle.java b/src/be/nikiroo/utils/resources/Bundle.java index 84efcea..fe3ac1a 100644 --- a/src/be/nikiroo/utils/resources/Bundle.java +++ b/src/be/nikiroo/utils/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) {