I’m trying to get name and last name from Contacts and store the values in a couple of NSString:
CFStringRef cfName = ABRecordCopyValue(person, kABPersonFirstNameProperty);
self.stName = (NSString *)cfName;
CFRelease(cfName);
CFStringRef cfLastname = ABRecordCopyValue(person, kABPersonLastNameProperty);
self.stLastname = (NSString *)cfLastname;
CFRelease(cfLastname);
The problem is, if firstname or lastname are empty in contacts, when I release the CFStringRef the app crash with EXC_BAD_ACCESS (zombie?).
If I don’t release the CFStringRef I have a leak.
Any suggestion is appreciated.
Max
Yes,
CFReleasewill crash (halt) if you pass it aNULLargument.This was allready mentioned by sbooth here.
CFReleaselooks like this:source
Therefor it’s your responcibility to check if you’re passing it a
NULLor not.You were correct in your (deleted) answer. Code should look like:
You still might get compiler warnings but this code should work fine.