2012-03-25 41 views
0

我被困在這個方法中,我不知道爲什麼! 任何人都可以指向我的一些源代碼? 非常感謝! 這是我的源代碼:爲NSData分配數據時發生卡滯/泄漏?

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; 
....... 
readData = [readFileHandle readDataOfLength:defaultLen] 
NSData *decryptedData = nil; 
//check is last buffer of file 
NSUInteger exLen = [readData length] % 16; 
NSUInteger decryptionLen = [readData length] - exLen; 
NSData *dataForDecryption = nil; 
    if(exLen != 0) 
    { 

    stuck at here-> [readData getBytes:dataForDecryption length:decryptionLen]; 
     // 
     decryptedData = [dataForDecryption AES256DecryptWithKey:KEY]; 
     self.isEndOfFile = YES; 
    } 
    else 
     decryptedData = [readData AES256DecryptWithKey:KEY]; 
[readFileHandle closeFile]; 
....... 
[pool drain]; 

我已經使用了一些功能,如:

NSData *dataForDecryption = [[[NSData alloc] initWithBytes:readData length:decryptionLen]autorelease]; 
NSData *dataForDecryption = [NSData dataWithBytes:readData length:decryptionLen]; 

,但我得到了同樣的錯誤。 當我使用 dataForDecryption = [readFileHandle readDataOfLength:decryptionLen]; 它堅持在上面的pos和大小讀爲0,雖然它不是EOF。

感謝

回答

0
stuck at here-> [readData getBytes:dataForDecryption length:decryptionLen]; 

你傳遞dataForDecryption,這是一個NSData*,但參數應該是一個緩衝,即void*。如果你想要一個NSData*,你應該使用像subdataWithRange:這樣的方法。

dataForEncryption = [readData subdataWithRange:NSRangeMake(0, decryptionLen)]; 
+0

不錯的推薦,謝謝Caleb :) – 2012-03-26 02:09:11