CFAllocatorSetDefault causes crashes

Originator:mayoff
Number:rdar://14185614 Date Originated:18-Jun-2013 01:43 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 4.6.3
Classification:Crash/Hang/Data Loss Reproducible:Always
 
18-Jun-2013 01:43 AM Rob Mayoff:
Summary:

Calling CFAllocatorSetDefault with anything but kCFAllocatorSystemDefault causes crashes.

Steps to Reproduce:

Call CFAllocatorSetDefault with any (valid) allocator.  Example:

int main(int argc, char *argv[])
{
    CFAllocatorSetDefault(kCFAllocatorMalloc);
    @autoreleasepool {
        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
    }
}

I have attached a test project with this code.  It crashes on both simulator and device.  Changing kCFAllocatorMalloc to kCFAllocatorSystemDefault removes the crash.

Expected Results:

Not crash.

Actual Results:

The app crashes soon after it changes the default allocator, the next time anything tries to create a Core Foundation object using NULL as the allocator.  The crash is in CFRetain, because CFRetain is being called with a NULL pointer.

Regression:

Notes:

The error is in _CFRuntimeCreateInstance.  When the allocator argument is NULL, and the current default allocator isn't the system default allocator, _CFRuntimeCreateInstance tries to retain the allocator.  But it just tries to retain the NULL instead of retaining the current default allocator.

See this stackoverflow question and my answer: http://stackoverflow.com/a/17138252/77567

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!