簡體   English   中英

NSInputStream打開BAD_ACCESS

[英]NSInputStream open BAD_ACCESS

以下是我的將日志文件上傳到FTP的代碼,問題是執行[mInputStream open]時有時會崩潰。 XCode向我展示BAD_ACCESS。 我想這可能是由於上傳了一個大文件而導致的。 但是,即使文件很小,有時也會發生BADACCESS。 所以我想尺寸不是主要原因。 有人可以幫忙嗎? 太感謝了。

NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

BOOL success;

NSURL *url;
CFWriteStreamRef ftpStream;

mFinish = NO;

mUploadPath = [[NSString alloc] initWithFormat:@"%@/%@",[UtilityHelper logFolderPath],   [mPathList objectAtIndex:0]]; 

//NSLog(@"mUpLoadPath:%d",[mUploadPath retainCount]);
[mPathList removeObjectAtIndex:0];

// check url
url = [UtilityHelper smartURLForString:FTP_URL];
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", url.absoluteString, [[UIDevice currentDevice] uniqueIdentifier]]];
success = (url != nil);

if (success) {        
    url = [NSMakeCollectable(CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url, (CFStringRef) [mUploadPath lastPathComponent], false) ) autorelease];
    success = (url != nil);
}else
    return;

mInputStream = [[NSInputStream inputStreamWithFileAtPath:mUploadPath] retain];
[mInputStream open];

// Create CFFTPStream for the URL
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);

assert(ftpStream != NULL);

mNetworkStream = [(NSOutputStream*)ftpStream retain];

NSLog(@"<<<<<<**>retain count:%d", [mNetworkStream retainCount]);

success = [mNetworkStream setProperty:FTP_USERNAME forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);

success = [mNetworkStream setProperty:FTP_PWD forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);

//[mNetworkStream self
mNetworkStream.delegate = self;

[mNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

[mNetworkStream open];

CFRelease(ftpStream); 

[pool release];

首先, retainCount是胡說八道。 不要這樣 不要試圖了解返回的值。

其次,您的應用程序崩潰了。 這意味着有崩潰日志或回溯記錄。 發表它。

最后,您的問題被標記為iOS,但您正在調用NSMakeCollectible() 那沒有道理。 另外,這里似乎存在許多內存管理問題。 您是否嘗試過構建和分析?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM