Question

Crashlog:

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x12121212

libobjc.A.dylib - objc_msgSend - isEqual:
CoreFoundation  - -[__NSDictionaryM setObject:forKey:]

Code:

if (object) {
    [_objects setObject:object forKey:key];
}

When init of _objects happens earlier in code:

- (id)init {
     self = [super init];
     if (self) {
         _objects = [[NSMutableDictionary alloc] init];
     }
     return self;
}

Object can be nil value, thats why I'm checking if it exist:

AFHTTPRequestOperation *object = [[AFHTTPRequestOperation alloc] initWithRequest:request];

I'm not sure what exactly can cause it. Crash happens very rarely, I'm unable to reproduce it, however a few users got it. I assume something got deallocated, could it be that _objects is nil? Or whole controller got deallocated? Why I can see isEqual in the log?

Can this fix the issue?

if (object && _objects) {
    [_objects setObject:object forKey:key];
}
Was it helpful?

Solution

You have checked not null condition for the dictionary and object value. Try to check nil condition for your key of object. There might be a case where key can be nil.

if (object && _objects && key) {
    [_objects setObject:object forKey:key];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top