Kaydet (Commit) 736f265c authored tarafından Stephan Bergmann's avatar Stephan Bergmann

cid#1326523,1326524: Resource leak on an exceptional path

Change-Id: I34016e7124ff33700bb33801145f478ed34e9262
üst 09fc095d
...@@ -60,18 +60,28 @@ final class WinRegKey { ...@@ -60,18 +60,28 @@ final class WinRegKey {
if ( is != null ) { if ( is != null ) {
// generate a temporary name for lib file and write to temp // generate a temporary name for lib file and write to temp
// location // location
BufferedInputStream istream = new BufferedInputStream( is ); File libfile;
File libfile = File.createTempFile( "unowinreg", ".dll" ); BufferedInputStream istream = null;
libfile.deleteOnExit(); // ensure deletion BufferedOutputStream ostream = null;
BufferedOutputStream ostream = new BufferedOutputStream( try {
new FileOutputStream( libfile ) ); istream = new BufferedInputStream( is );
int bsize = 2048; int n = 0; libfile = File.createTempFile( "unowinreg", ".dll" );
byte[] buffer = new byte[bsize]; libfile.deleteOnExit(); // ensure deletion
while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) { ostream = new BufferedOutputStream(
ostream.write( buffer, 0, n ); 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 // load library
System.load( libfile.getPath() ); System.load( libfile.getPath() );
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment