Author: nextgens
Date: 2008-04-14 03:54:31 +0000 (Mon, 14 Apr 2008)
New Revision: 19297

Modified:
   trunk/freenet/src/freenet/support/io/BaseFileBucket.java
Log:
fix #729 and #963: Temporary files grow until fill disk

Modified: trunk/freenet/src/freenet/support/io/BaseFileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/BaseFileBucket.java    2008-04-14 
03:28:27 UTC (rev 19296)
+++ trunk/freenet/src/freenet/support/io/BaseFileBucket.java    2008-04-14 
03:54:31 UTC (rev 19297)
@@ -393,17 +393,27 @@

                if(toClose != null) {
                        Logger.error(this, "Streams open free()ing "+this+" : 
"+StringArray.toString(toClose), new Exception("debug"));
-                       for(int i=0;i<toClose.length;i++) {
-                               try {
-                                       if(toClose[i] instanceof 
FileBucketOutputStream) {
-                                               ((FileBucketOutputStream) 
toClose[i]).close();
-                                       } else {
-                                               ((FileBucketInputStream) 
toClose[i]).close();
+                       double toCloseLength = toClose.length;
+                       while(toCloseLength > 0) {
+                               int toCloseThisRound;
+                               if(toCloseLength <= Integer.MAX_VALUE) {
+                                       toCloseThisRound = (int) toCloseLength;
+                                       toCloseLength = 0;
+                               } else 
+                                       toCloseLength -= (toCloseThisRound = 
Integer.MAX_VALUE);
+
+                               for(int i=0; i<toCloseThisRound; i++) {
+                                       try {
+                                               if(toClose[i] instanceof 
FileBucketOutputStream) {
+                                                       
((FileBucketOutputStream) toClose[i]).close();
+                                               } else {
+                                                       
((FileBucketInputStream) toClose[i]).close();
+                                               }
+                                       } catch (IOException e) {
+                                               Logger.error(this, "Caught 
closing stream in free(): "+e, e);
+                                       } catch (Throwable t) {
+                                               Logger.error(this, "Caught 
closing stream in free(): "+t, t);
                                        }
-                               } catch (IOException e) {
-                                       Logger.error(this, "Caught closing 
stream in free(): "+e, e);
-                               } catch (Throwable t) {
-                                       Logger.error(this, "Caught closing 
stream in free(): "+t, t);
                                }
                        }
                }


Reply via email to