简体   繁体   中英

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]. 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];

First, retainCount is nonsense. 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() ; that doesn't make sense. Also, there appear to be a number of memory management issues here. Did you try Build and Analyze?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM