[英]NSInputStream open BAD_ACCESS
The below is my code to upload log files to FTP, and the problem is sometimes it crashes when execute [mInputStream open]. 以下是我的将日志文件上传到FTP的代码,问题是执行[mInputStream open]时有时会崩溃。 XCode show me BAD_ACCESS.
XCode向我展示BAD_ACCESS。 I guess it may result from uploading a big-size file.
我想这可能是由于上传了一个大文件而导致的。 However, BADACCESS sometimes happens, even file size is small.
但是,即使文件很小,有时也会发生BADACCESS。 So I guess size is not the main reason.
所以我想尺寸不是主要原因。 Anyone can help?
有人可以帮忙吗? Thanks a million.
太感谢了。
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];
First, retainCount
is nonsense. 首先,
retainCount
是胡说八道。 Don't call it. 不要这样 Don't try to understand the value returned.
不要试图了解返回的值。
Secondly, your app is crashing. 其次,您的应用程序崩溃了。 That means there is a crash log or backtrace.
这意味着有崩溃日志或回溯记录。 Post it.
发表它。
Finally, your question is tagged iOS, but you are calling NSMakeCollectible()
; 最后,您的问题被标记为iOS,但您正在调用
NSMakeCollectible()
; that doesn't make sense. 那没有道理。 Also, there appear to be a number of memory management issues here.
另外,这里似乎存在许多内存管理问题。 Did you try Build and Analyze?
您是否尝试过构建和分析?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.