crash in objc_object::release()

we have a crash in our app, here is the call stack:


EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000e4f52bec8


#17. Crashed: com.apple.NSURLSession-work

0 libobjc.A.dylib 0x184c997f4 objc_object::release() + 8

1 CoreFoundation 0x1861020a8 -[__NSDictionaryI dealloc] + 136

2 Foundation 0x186c0cb34 -[NSError dealloc] + 68

3 CFNetwork 0x186a75fbc -[__NSCFURLSessionTask dealloc] + 480

4 CFNetwork 0x18683bab0 -[__NSCFLocalSessionTask dealloc] + 444

5 libsystem_blocks.dylib 0x185127a68 _Block_release + 160

6 libdispatch.dylib 0x1850d29a0 _dispatch_client_callout + 16

7 libdispatch.dylib 0x1850df604 _dispatch_continuation_pop + 448

8 libdispatch.dylib 0x1850d4930 _dispatch_source_invoke + 948

9 libdispatch.dylib 0x1850e0964 _dispatch_queue_serial_drain + 560

10 libdispatch.dylib 0x1850d62cc _dispatch_queue_invoke + 884

11 libdispatch.dylib 0x1850e2a50 _dispatch_root_queue_drain + 540

12 libdispatch.dylib 0x1850e27d0 _dispatch_worker_thread3 + 124

13 libsystem_pthread.dylib 0x1852db100 _pthread_wqthread + 1096

14 libsystem_pthread.dylib 0x1852dacac start_wqthread + 4



do you have any ideas what can cause such a crash?

Replies

According to line 5 of the backtrace, a block (most likely a NSURLSession completion handler block, according to lines 3-4) is being deallocated. Within that, a NSError object is being deallocated (line 2), possibly an input parameter to the block, and within that a dictionary is being deallocated (line 1), probably the userInfo dict. The crash occurred because the dictionary reference is invalid, or a key or value in the dictionary is invalid.


Are you using ARC, or manual memory management? It could be something as simple as an over-release, though KERN_INVALID_ADDRESS seems like an unusual error to get in that case.

yes we are using ARC

it seems like a problem in NSError, isnt it?


can the userInfo dict, contain values that our app allocated ?

Yes, userInfo can contain objects your app created.


It's unlikely to be a problem in NSError itself. It may not be the userInfo dictionary.


What platform is this — iOS or macOS? Is your code pure Obj-C, or is there a mixture of languages (e.g. C, C++ or Obj-C++)? If you can make the problem repeatable, you might get some ideas about where it's going wrong.


You could also try using Instruments (Allocations) to track the allocation history of objects in your app. If there's an overrelease, you might be able to see it there.

its iOS platform


our code is obj-c and swift, but maybe some pods contain c or c++


can you give me example of how can userinfo dictionary contain objects created by our app?


thnx

>> can you give me example of how can userinfo dictionary contain objects created by our app?


It can't just happen, you would have to have code to add userInfo entries manually, so if you don't have any such code that's probably not the problem.


The other possibility is an edge case when you pass a NSError** outError parameter in Obj-C. By default, such a parameter has the "autoreleasing" attribute, which can cause the error object to be released unexpectedly when the autorelease pool it's in is drained. This scenario doesn't happen in ordinary circumstances, but if the outError parameter is captured by a block/closure, you might be vulnerable.


Xcode 9 has a (new?) warning about autoreleasing parameters being captured by closures, at least in Swift. If you're desperate, you could try converting a copy of your app for Xcode 9/Swift 4, and see if there are any warnings. (I wouldn't recommend converting permanently while Xcode 9 is still in beta, though.)