From 59e9bd1e353b9d01cee7da6055ebd36d8d045d3a 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 --- src/be/nikiroo/utils/resources/Bundle.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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) { -- 2.27.0