From 77dde5711ba53ffeeeea8b06c97de2ecc00715e0 Mon Sep 17 00:00:00 2001
From: jrandom <jrandom>
Date: Thu, 2 Sep 2004 05:40:25 +0000
Subject: [PATCH] more aggressively delete the temp lib file

---
 .../java/src/freenet/support/CPUInformation/CPUID.java | 10 ++++++++--
 core/java/src/net/i2p/util/NativeBigInteger.java       | 10 ++++++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java
index 1dc94a72f5..593f72f7bd 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 9fbc633d6a..261651c7a6 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();
             }
         }
     }
-- 
GitLab