Author: nextgens
Date: 2008-02-15 06:22:08 +0000 (Fri, 15 Feb 2008)
New Revision: 17918

Modified:
   trunk/freenet/src/net/i2p/util/NativeBigInteger.java
Log:
NativeBigInteger: fix a potential FD leak

Modified: trunk/freenet/src/net/i2p/util/NativeBigInteger.java
===================================================================
--- trunk/freenet/src/net/i2p/util/NativeBigInteger.java        2008-02-15 
06:19:18 UTC (rev 17917)
+++ trunk/freenet/src/net/i2p/util/NativeBigInteger.java        2008-02-15 
06:22:08 UTC (rev 17918)
@@ -26,6 +26,7 @@
 import freenet.support.CPUInformation.CPUInfo;
 import freenet.support.CPUInformation.IntelCPUInfo;
 import freenet.support.CPUInformation.UnknownCPUException;
+import freenet.support.io.Closer;

 /**
  * <p>BigInteger that takes advantage of the jbigi library for the modPow 
operation,
@@ -471,24 +472,26 @@
                        throw new FileNotFoundException();
                }

+               FileOutputStream fos = null;
                try {
                        f.deleteOnExit();
-                       FileOutputStream fos = new FileOutputStream(f);
+                       fos = new FileOutputStream(f);
                        byte[] buf = new byte[4096 * 1024];
                        int read;
                        while((read = is.read(buf)) > 0) {
                                fos.write(buf, 0, read);
                        }
                        fos.close();
+                       fos = null;
                        System.load(f.getAbsolutePath());
                        return true;
                } catch(IOException e) {
                } catch(UnsatisfiedLinkError ule) {
-                       f.delete();
                        // likely to be "noexec" 
                        if(ule.toString().toLowerCase().indexOf("not 
permitted") == -1)
                                throw ule;
                } finally {
+                       Closer.close(fos);
                        f.delete();
                }



Reply via email to