Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve KERN_PROTECTION_FAILURE and KERN_INVALID_ADDRESS?

How can you solve a KERN_PROTECTION_FAILURE and a KERN_INVALID ADDRESS? Both seem to happen at exactly the same spot when I run my app.

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x6d783f44
Crashed Thread:  2

Thread 2 Crashed:
0   libobjc.A.dylib                 0x34a80464 objc_msgSend + 16
1   Foundation                      0x31171dda __+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_7 + 10
2   libSystem.B.dylib               0x30dd9678 _dispatch_call_block_and_release + 12
3   libSystem.B.dylib               0x30dd9b98 _dispatch_worker_thread2 + 120
4   libSystem.B.dylib               0x30d7e24a _pthread_wqthread + 258
5   libSystem.B.dylib               0x30d76970 start_wqthread + 0

And:

Exception Type:  EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x00000011
Crashed Thread:  7

Thread 7 Crashed:
0   libobjc.A.dylib                 0x34a80464 objc_msgSend + 16
1   Foundation                      0x31171dfc -[NSOperation completionBlock] + 16
2   Foundation                      0x31171dda __+[__NSOperationInternal _observeValueForKeyPath:ofObject:changeKind:oldValue:newValue:indexes:context:]_block_invoke_7 + 10
3   libSystem.B.dylib               0x30dd9678 _dispatch_call_block_and_release + 12
4   libSystem.B.dylib               0x30dd9b98 _dispatch_worker_thread2 + 120
5   libSystem.B.dylib               0x30d7e24a _pthread_wqthread + 258
6   libSystem.B.dylib               0x30d76970 start_wqthread + 0

Weird thing is, it crashes on an iPad 1 (iOS 4.2.1) but not on an iPad 2 (iOS 4.3.2). Could this maybe be a problem with the iPad itself or maybe with the memory? Or is it truly a bug in my code? If so, why can't I reproduce it on the iPad 2?

like image 515
pkoning Avatar asked Jun 09 '11 12:06

pkoning


People also ask

What does Kern_invalid_address mean?

EXC_BAD_ACCESS (SIGSEGV) KERN_INVALID_ADDRESS means that the virtual address you're refererencing is not in the page tables or you don't have access. It's a virtual address that you're not allowed to access.

What is Exc_bad_access Kern_invalid_address?

EXC_BAD_ACCESS KERN_INVALID_ADDRESS crash is not due to memory leak, but due to the attempt to access an deallocated object. Example: if you used __weak typeof(self) weakSelf = self; and object has been released before you accessing it inside block you'll got the crash.


1 Answers

EXC_BAD_ACCESS errors are typically from trying to send a message to an object that has been deallocated. In this case, it appears to be something in your NSOperation that has been released already. This is almost certainly a bug in your code. As for why it happens on one iPad and not the other, it could be that on one device the memory that used to contain your object has been reused but on the other it still has a zombie of your object.

A much more thorough explanation is here.

like image 141
highlycaffeinated Avatar answered Oct 03 '22 15:10

highlycaffeinated