diff options
author | Caolán McNamara <caolanm@redhat.com> | 2022-09-07 16:55:41 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2022-09-15 15:30:35 +0200 |
commit | b370b510af613303e4856ab8de7b394dc4cd3bef (patch) | |
tree | c73c5dd723cc5bfb2943796cdb5c5d8404f7d31e /odk/source | |
parent | f634834434414c8b8d7ad28063bed08b683765a2 (diff) |
cid#1500416 Resource leak
Change-Id: I090e10604562665cf22aa98758e81dd398f4f9c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139997
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/Loader.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/odk/source/com/sun/star/lib/loader/Loader.java b/odk/source/com/sun/star/lib/loader/Loader.java index bc1a3c3e7bb0..5aae9848d775 100644 --- a/odk/source/com/sun/star/lib/loader/Loader.java +++ b/odk/source/com/sun/star/lib/loader/Loader.java @@ -199,6 +199,15 @@ public final class Loader { } } + private static void close(InputStream c) { + if (c == null) return; + try { + c.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + private static void callUnoinfo(String path, ArrayList<URL> urls) { Process p; try { @@ -214,9 +223,10 @@ public final class Loader { int code; byte[] buf = new byte[1000]; int n = 0; + InputStream is = null; try { - InputStream s = p.getInputStream(); - code = s.read(); + is = p.getInputStream(); + code = is.read(); for (;;) { if (n == buf.length) { if (n > Integer.MAX_VALUE / 2) { @@ -229,7 +239,7 @@ public final class Loader { System.arraycopy(buf, 0, buf2, 0, n); buf = buf2; } - int k = s.read(buf, n, buf.length - n); + int k = is.read(buf, n, buf.length - n); if (k == -1) { break; } @@ -240,7 +250,10 @@ public final class Loader { "com.sun.star.lib.loader.Loader::getCustomLoader: reading" + " unoinfo output: " + e); return; + } finally { + close(is); } + int ev; try { ev = p.waitFor(); |