We started seeing crashes that happen when our app starts. I wasn't able to reproduce it, and it happens only to a few users.
The exception is: Exception Type: EXC_BAD_ACCESS Code: KERN_INVALID_ADDRESS at 0x3250974659
The crash happened in a thread named com.apple.NSURLConnectionLoader when calling -[NSBlockOperation main]
This is the stack trace of that thread:
0 libobjc.A.dylib objc_msgSend + 9 1 Foundation -[NSBlockOperation main] + 200 2 Foundation -[__NSOperationInternal start] + 840 3 Foundation -[_NSCFURLProtocolBridgeWithTrampoline processEventQ] + 344 4 Foundation -[_NSCFURLProtocolBridgeWithTrampoline pushEvent:from:] + 298 5 Foundation -[_NSCFURLProtocolBridge stop] + 88 6 Foundation _bridger + 64 7 CFNetwork __block_global_7 + 24 8 CFNetwork __block_global_8 + 12 9 CFNetwork ___performAsync_block_invoke_068 + 18 10 CoreFoundation CFArrayApplyFunction + 176 11 CFNetwork RunloopBlockContext::perform() + 74 12 CFNetwork MultiplexerSource::perform() + 188 13 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14 14 CoreFoundation __CFRunLoopDoSources0 + 212 15 CoreFoundation __CFRunLoopRun + 646 16 CoreFoundation CFRunLoopRunSpecific + 356 17 CoreFoundation CFRunLoopRunInMode + 104 18 Foundation +[NSURLConnection(Loader) _resourceLoadLoop:] + 308 19 Foundation __NSThread__main__ + 972 20 libsystem_c.dylib _pthread_start + 308
Would appreciate any help to understand what's can cause this kind of crash.
With me this code indirectly is causing the crash. If I read the crash dump correctly
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]
is triggering the NSURLConnectionLoaderThread. This is probably what they use for Asynchronous support. But as I use synchronous request, there is no way I can deallocate an object while the thread is running. If you ask me, that is a bug in IOS 7.
NSMutableURLRequest* request = [self setupRequestWithService:service andMethod:operation];
[request addValue:CONTENT_TYPE_APPLICATION_JSON forHTTPHeaderField:REQUEST_HEADER_CONTENT_TYPE];
[request setHTTPMethod:@"POST"];
NSError* error = nil;
NSData* jsonData = nil;
NSAssert(message,@"Message must not be null");
jsonData = [NSJSONSerialization dataWithJSONObject:[message toDictionary] options:kNilOptions error:&error];
NSAssert(! error, @"Message could not be json serialized");
Log(@"----------------------------------------------------------------------");
Log(@"JSON DATA: - %@", [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding]);
Log(@"----------------------------------------------------------------------");
[request setHTTPBody:jsonData];
// Send Synchronous Request
NSURLResponse *response = nil;
error = nil;
NSData* responseData = nil;
NSString* responseString = nil;
responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
My guess (because without code all answers will be guessing) - is you're deallocating objects you are using in blocks before blocks executes.
Paste a code so we can help more.
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.