2012-03-25 45 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