CFRelease crash

Crash on CFRelease(res)

, below is the codes, please help how to fix it.
    {
        dispatch_block_t block = ^{
            //All this dancing is an attempt to work around some weird crash:
            //seems like ARC is trying to release NULL before assigning new value
            CFDictionaryRef res = SCDynamicStoreCopyMultiple(store, NULL, keyPatterns);
            if (res && store) {
                NSDictionary *nsRes = (__bridge_transfer NSDictionary *)CFPropertyListCreateDeepCopy(kCFAllocatorDefault,
                                                                                                     (CFPropertyListRef)res,
                                                                                                     kCFPropertyListImmutable);
                setDynamicStore(nsRes);
            } else {
                ZLogError("SCU:[%s]%s refreshDynamicStore failed",
                          dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL),
                          __FUNCTION__);
                setDynamicStore(NULL);
            }
            if(res) {
                CFRelease(res);
            }
        };
        if (dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL) == dispatch_queue_get_label(queue)) {
            block();
        } else {
            dispatch_async(queue, block);
        }
    }

How reproducible is this crash? Can you reproduce it reliably in your office? Or are you chasing bug reports coming in from the field?

Also, if you put that code into a small test project and run it with the standard memory debugging tools, does it crash there?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

CFRelease crash
 
 
Q