Author: toad
Date: 2007-05-03 21:54:35 +0000 (Thu, 03 May 2007)
New Revision: 13135

Modified:
   trunk/freenet/src/freenet/support/RandomGrabArray.java
Log:
Fix memory leak

Modified: trunk/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomGrabArray.java      2007-05-03 
21:49:12 UTC (rev 13134)
+++ trunk/freenet/src/freenet/support/RandomGrabArray.java      2007-05-03 
21:54:35 UTC (rev 13135)
@@ -53,7 +53,7 @@
        }

        public RandomGrabArrayItem removeRandom() {
-               RandomGrabArrayItem ret;
+               RandomGrabArrayItem ret, oret;
                synchronized(this) {
                        boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
                        while(true) {
@@ -63,6 +63,7 @@
                                }
                                int i = rand.nextInt(index);
                                ret = reqs[i];
+                               oret = ret;
                                if(ret.isCancelled()) ret = null;
                                if(ret != null && !ret.canRemove()) {
                                        ret.setParentGrabArray(null);
@@ -70,8 +71,8 @@
                                }
                                reqs[i] = reqs[--index];
                                reqs[index] = null;
-                               if(ret != null)
-                                       contents.remove(ret);
+                               if(oret != null)
+                                       contents.remove(oret);
                                // Shrink array
                                if((index < reqs.length / 4) && (reqs.length > 
MIN_SIZE)) {
                                        // Shrink array


Reply via email to