2
votes

I am seeing EXC_BAD_ACCESS KERN_INVALID_ADDRESS for class method.

From what I understand, I should not be seeing this for class/static methods.

Am I missing something?

Stack Trace:

Thread : Crashed: com.apple.root.user-initiated-qos

0 libobjc.A.dylib 0x0000000196eac0b4 objc_retain + 20

1 $APP_NAME 0x00000001002611a8 +[$CLASS_NAME $METHOD_NAME:] ($CLASS_NAME.m:590)

2 libdispatch.dylib 0x0000000197511994 _dispatch_call_block_and_release + 24

3 libdispatch.dylib 0x0000000197511954 _dispatch_client_callout + 16

4 libdispatch.dylib 0x000000019751e780 _dispatch_root_queue_drain + 1848

5 libdispatch.dylib 0x000000019751fc4c _dispatch_worker_thread3 + 108

6 libsystem_pthread.dylib 0x00000001976f121c _pthread_wqthread + 816

7 libsystem_pthread.dylib 0x00000001976f0ee0 start_wqthread + 4

3
It depends on what is being accessed. Do you have a stack trace?Phillip Mills
@Phillip Mills It is a simple tracking method, making call to analytics library.k-thorat
What does line 590 in $CLASS_NAME.m look like?Phillip Mills
Line 590 is name of the class method -> + (void)methodName:(NSObject*)modelk-thorat

3 Answers

8
votes

I have seen this crash a few times (with very similar, if not identical stack traces), and found that it had to do with a nonatomic property being set with a new object, while simultaneously being read.

That objc_retain +20 instruction turned out to be a call on the isa property of the object being read-- but at that point the object is already released and the isa pointer is changed to a bad address

I was able to debug my issue by following this blog post by Mike Ash: https://www.mikeash.com/pyblog/tales-from-the-crash-mines-issue-1.html

I would highly recommend reading the entire thing through-- it involves using the disassembler to debug, but it was definitely a lifesaver for us on multiple occasions

EDIT: Note that I am definitely not even 50% sure that this is your issue, but I hope that my anecdotal experience could save you some time. I know that I've spent many work weeks debugging issues that looked like this, but I still was never 100%

1
votes

This crash happen because of dangling pointer. For example, when variables or objects is trying to access an object that's already been de-allocated.

P.S: Most people might confused about "memory leak" and "dangling pointer"

Dangling pointer occurs when a pointer references memory that has been de-allocated. Memory Leak occurs when memory is still allocated but nothing references it.

0
votes

EXC_BAD_ACCESS generally means that you are sending a objective C message to an invalid memory address.

It may cause:

1. An object that you want to use which has been deallocated.
2. When any variable or object is trying to access restricted memory. That means such crash occurs due to memory leak.