diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-08-18 12:14:36 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-08-18 16:05:26 +0200 |
commit | 6105706deb71aa134f2f754aed6f50daf3b8d620 (patch) | |
tree | c25ddd93b485fdfe7bded3e8145a291b70c5324c /odk/source | |
parent | 1ad2d1336a3f82e13e2bdfe979154c3a8c936ed6 (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.java | 16 |
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); + } } } |