The below is my code to upload log files to FTP, and the problem is sometimes it crashes when execute [mInputStream open]. XCode show me BAD_ACCESS. I guess it may result from uploading a big-size file. However, BADACCESS sometimes happens, even file size is small. 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];