Author: toad
Date: 2007-08-06 22:02:15 +0000 (Mon, 06 Aug 2007)
New Revision: 14497
Modified:
trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
Log:
Fix ArrayIndexOutOfBounds when a cancelled request is sent.
Modified: trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
===================================================================
--- trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2007-08-06 21:21:41 UTC (rev 14496)
+++ trunk/freenet/src/freenet/client/async/SplitFileFetcherSegment.java
2007-08-06 22:02:15 UTC (rev 14497)
@@ -22,6 +22,7 @@
import freenet.keys.ClientCHK;
import freenet.keys.ClientCHKBlock;
import freenet.keys.ClientKeyBlock;
+import freenet.keys.NodeCHK;
import freenet.support.Logger;
import freenet.support.api.Bucket;
import freenet.support.io.BucketTools;
@@ -323,7 +324,7 @@
if(logMINOR) Logger.minor(this, "Permanently failed block:
"+blockNo+" on "+this+" : "+e, e);
boolean allFailed;
// Since we can't keep the key, we need to unregister for it at
this point to avoid a memory leak
- seg.unregisterKey(getBlockKey(blockNo).getNodeKey());
+ seg.unregisterKey(getBlockNodeKey(blockNo));
synchronized(this) {
if(isFinishing()) return; // this failure is now
irrelevant, and cleanup will occur on the decoder thread
if(blockNo < dataKeys.length) {
@@ -455,11 +456,19 @@
}
public ClientCHK getBlockKey(int blockNum) {
- if(blockNum < dataKeys.length)
+ if(blockNum < 0) return null;
+ else if(blockNum < dataKeys.length)
return dataKeys[blockNum];
- else
+ else if(blockNum < dataKeys.length + checkKeys.length)
return checkKeys[blockNum - dataKeys.length];
+ else return null;
}
+
+ public NodeCHK getBlockNodeKey(int blockNum) {
+ ClientCHK key = getBlockKey(blockNum);
+ if(key != null) return key.getNodeCHK();
+ else return null;
+ }
public synchronized void removeSeg(SplitFileFetcherSubSegment segment) {
for(int i=0;i<subSegments.size();i++) {