EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000 on NSUserDefaults getValueForKey: method.

926 Views Asked by At

I have a weird crash while using NSUserDefaults and I'm unable to reproduce this myself but I get this reported from Crashlytics from one of user's devices.

Exception: EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000

Crashed: com.apple.NSURLConnectionLoader
0  libobjc.A.dylib                0x22613a76 objc_msgSend + 21
1  CoreFoundation                 0x22e97a58 __CFBasicHashDrain + 448
2  CoreFoundation                 0x22d77795 CFRelease + 424
3  CoreFoundation                 0x22e979e8 __CFBasicHashDrain + 336
4  CoreFoundation                 0x22d77795 CFRelease + 424
5  CoreFoundation                 0x22e26b8f -[CFPrefsSearchListSource alreadylocked_copyDictionary] + 906
6  CoreFoundation                 0x22e258ad -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] + 52
7  CoreFoundation                 0x22e9f6bb -[CFPrefsSource copyValueForKey:] + 50
8  CoreFoundation                 0x22ea1e3d ___CFPreferencesCopyAppValueWithContainerAndConfiguration_block_invoke + 28
9  CoreFoundation                 0x22e23969 __95+[CFPrefsSearchListSource withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 400
10 CoreFoundation                 0x22e2377f normalizeQuintuplet + 354
11 CoreFoundation                 0x22e23617 +[CFPrefsSearchListSource withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 106
12 CoreFoundation                 0x22ea1dc9 _CFPreferencesCopyAppValueWithContainerAndConfiguration + 248
13 Foundation                     0x235c436f -[NSUserDefaults(NSUserDefaults) objectForKey:] + 46
14 MyApp                       0x12ddc49 -[MyStore getConfigValue:] (MyStore.m:43)

The code in MyStore is as below:

- (id) getConfigValue:(NSString *)key {
    if (key) {
        return [[NSUserDefaults standardUserDefaults] valueForKey:key];
    }
    return nil;
}

And I call this method as below

NSString *userId = [storeObj getConfigValue:@"UserID"];

Now, this value may not be set in some cases but that should just return nil. I'm unable to find any valid reason for this to crash.

Thanks for help.

0

There are 0 best solutions below