summaryrefslogtreecommitdiff
path: root/odk
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2016-02-24 14:00:50 +0100
committerStephan Bergmann <sbergman@redhat.com>2016-02-24 14:00:50 +0100
commit736f265c46130ce905be75f2141424486d52c8a9 (patch)
treec7b7aa660f5464b4823714c8ef2b44f96513cb8c /odk
parent09fc095dd47e9e1025fc185ed1a10826f481f0cb (diff)
cid#1326523,1326524: Resource leak on an exceptional path
Change-Id: I34016e7124ff33700bb33801145f478ed34e9262
Diffstat (limited to 'odk')
-rw-r--r--odk/source/com/sun/star/lib/loader/WinRegKey.java32
1 files changed, 21 insertions, 11 deletions
diff --git a/odk/source/com/sun/star/lib/loader/WinRegKey.java b/odk/source/com/sun/star/lib/loader/WinRegKey.java
index fad5d34a8a76..65b3963d8332 100644
--- a/odk/source/com/sun/star/lib/loader/WinRegKey.java
+++ b/odk/source/com/sun/star/lib/loader/WinRegKey.java
@@ -60,18 +60,28 @@ final class WinRegKey {
if ( is != null ) {
// generate a temporary name for lib file and write to temp
// location
- BufferedInputStream istream = new BufferedInputStream( is );
- File libfile = File.createTempFile( "unowinreg", ".dll" );
- libfile.deleteOnExit(); // ensure deletion
- BufferedOutputStream ostream = new BufferedOutputStream(
- new FileOutputStream( libfile ) );
- int bsize = 2048; int n = 0;
- byte[] buffer = new byte[bsize];
- while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) {
- ostream.write( buffer, 0, n );
+ File libfile;
+ BufferedInputStream istream = null;
+ BufferedOutputStream ostream = null;
+ try {
+ istream = new BufferedInputStream( is );
+ libfile = File.createTempFile( "unowinreg", ".dll" );
+ libfile.deleteOnExit(); // ensure deletion
+ ostream = new BufferedOutputStream(
+ new FileOutputStream( libfile ) );
+ int bsize = 2048; int n = 0;
+ byte[] buffer = new byte[bsize];
+ while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) {
+ ostream.write( buffer, 0, n );
+ }
+ } finally {
+ if (istream != null) {
+ istream.close();
+ }
+ if (ostream != null) {
+ ostream.close();
+ }
}
- istream.close();
- ostream.close();
// load library
System.load( libfile.getPath() );
} else {