diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java index 1dc94a72f54cf2b189cc07a13f8de0ee4df44624..593f72f7bd2cfa24481f109d4d78e1d741569b6c 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUID.java +++ b/core/java/src/freenet/support/CPUInformation/CPUID.java @@ -483,10 +483,11 @@ public class CPUID { } File outFile = null; + FileOutputStream fos = null; try { InputStream libStream = resource.openStream(); outFile = File.createTempFile(libPrefix + "jcpuid", "lib.tmp" + libSuffix); - FileOutputStream fos = new FileOutputStream(outFile); + fos = new FileOutputStream(outFile); byte buf[] = new byte[4096*1024]; while (true) { int read = libStream.read(buf); @@ -494,6 +495,7 @@ public class CPUID { fos.write(buf, 0, read); } fos.close(); + fos = null; System.load(outFile.getAbsolutePath());//System.load requires an absolute path to the lib return true; } catch (UnsatisfiedLinkError ule) { @@ -510,8 +512,12 @@ public class CPUID { } return false; } finally { + if (fos != null) { + try { fos.close(); } catch (IOException ioe) {} + } if (outFile != null) { - outFile.deleteOnExit(); + if (!outFile.delete()) + outFile.deleteOnExit(); } } } diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java index 9fbc633d6a77a688d2d704f9e80699f372f4b403..261651c7a635616eccb2d3cd6cdcb92f364ac0f6 100644 --- a/core/java/src/net/i2p/util/NativeBigInteger.java +++ b/core/java/src/net/i2p/util/NativeBigInteger.java @@ -482,10 +482,11 @@ public class NativeBigInteger extends BigInteger { } File outFile = null; + FileOutputStream fos = null; try { InputStream libStream = resource.openStream(); outFile = File.createTempFile(_libPrefix + "jbigi", "lib.tmp" + _libSuffix); - FileOutputStream fos = new FileOutputStream(outFile); + fos = new FileOutputStream(outFile); byte buf[] = new byte[4096*1024]; while (true) { int read = libStream.read(buf); @@ -493,6 +494,7 @@ public class NativeBigInteger extends BigInteger { fos.write(buf, 0, read); } fos.close(); + fos = null; System.load(outFile.getAbsolutePath()); //System.load requires an absolute path to the lib return true; } catch (UnsatisfiedLinkError ule) { @@ -509,8 +511,12 @@ public class NativeBigInteger extends BigInteger { } return false; } finally { + if (fos != null) { + try { fos.close(); } catch (IOException ioe) {} + } if (outFile != null) { - outFile.deleteOnExit(); + if (!outFile.delete()) + outFile.deleteOnExit(); } } }