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;
BufferedOutputStream ostream = null;
try {
istream = new BufferedInputStream( is );
libfile = File.createTempFile( "unowinreg", ".dll" );
libfile.deleteOnExit(); // ensure deletion libfile.deleteOnExit(); // ensure deletion
BufferedOutputStream ostream = new BufferedOutputStream( ostream = new BufferedOutputStream(
new FileOutputStream( libfile ) ); new FileOutputStream( libfile ) );
int bsize = 2048; int n = 0; int bsize = 2048; int n = 0;
byte[] buffer = new byte[bsize]; byte[] buffer = new byte[bsize];
while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) { while ( ( n = istream.read( buffer, 0, bsize ) ) != -1 ) {
ostream.write( buffer, 0, n ); ostream.write( buffer, 0, n );
} }
} finally {
if (istream != null) {
istream.close(); istream.close();
}
if (ostream != null) {
ostream.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