summaryrefslogtreecommitdiff
path: root/odk/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2022-08-18 12:14:36 +0100
committerCaolán McNamara <caolanm@redhat.com>2022-08-18 16:05:26 +0200
commit6105706deb71aa134f2f754aed6f50daf3b8d620 (patch)
treec25ddd93b485fdfe7bded3e8145a291b70c5324c /odk/source
parent1ad2d1336a3f82e13e2bdfe979154c3a8c936ed6 (diff)
cid#1500586 Resource leak
Change-Id: I32d837af7574f6eb4ac7db4759139d0b78f63e75 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138479 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'odk/source')
-rw-r--r--odk/source/com/sun/star/lib/loader/WinRegKey.java16
1 files changed, 15 insertions, 1 deletions
diff --git a/odk/source/com/sun/star/lib/loader/WinRegKey.java b/odk/source/com/sun/star/lib/loader/WinRegKey.java
index 3276458fc6f6..597b506d9ca2 100644
--- a/odk/source/com/sun/star/lib/loader/WinRegKey.java
+++ b/odk/source/com/sun/star/lib/loader/WinRegKey.java
@@ -20,6 +20,7 @@
package com.sun.star.lib.loader;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.regex.Matcher;
@@ -40,13 +41,23 @@ final class WinRegKey {
m_keyName = keyName;
}
+ private static void close(BufferedReader c) {
+ if (c == null) return;
+ try {
+ c.close();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+
/**
* Reads the default string value.
*/
public String getStringValue() throws WinRegKeyException {
+ BufferedReader r = null;
try {
Process p = Runtime.getRuntime().exec(new String[]{"reg", "QUERY", m_keyName});
- BufferedReader r = new BufferedReader(
+ r = new BufferedReader(
new InputStreamReader(p.getInputStream(), Charset.defaultCharset()));
String v = null;
Pattern pt = Pattern.compile("\\s+\\(Default\\)\\s+REG_SZ\\s+(.+)");
@@ -77,6 +88,9 @@ final class WinRegKey {
} catch (Exception e) {
throw new WinRegKeyException(e);
}
+ finally {
+ close(r);
+ }
}
}