0
ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for (int i=0; i < ABMultiValueGetCount(phonesRef); i++)
    {
        CFStringRef currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i);
        CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, i);

        if (currentPhoneLabel != nil && currentPhoneValue != nil)
        {
            if (CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo)
            {
                [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"workNumber"];
            }

            if (CFStringCompare(currentPhoneLabel, kABHomeLabel, 0) == kCFCompareEqualTo)
            {
                [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"homeNumber"];
            }
        }
        else if (currentPhoneValue != nil && currentPhoneLabel == nil)
        {
            [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"workNumber"];
        }

        CFRelease(currentPhoneLabel);
        CFRelease(currentPhoneValue);
    }
    CFRelease(phonesRef);

Here is my code for importing contact phones into my ios app, but when currentPhoneLabel is nil xocde for CFRelease(currentPhoneLabel). I don't know why is it happening. Any help would be much appreciable.

Thanks

Paras Gorasiya
  • 1,295
  • 2
  • 13
  • 33
  • I refer from below stackoverflow answers which about memory release , by your crash log, if there is no data in that label, how it release memory? it should be crash right? http://stackoverflow.com/questions/17959760/do-i-need-to-manually-release-cfstringref – S. Karthik Dec 24 '15 at 10:31

1 Answers1

0

You already have guards in other places in the code, so you just need to add a guard on every call to CFRelease() as well:

if (currentPhoneLabel != NULL)
    CFRelease(currentPhoneLabel);
// etc.
trojanfoe
  • 120,358
  • 21
  • 212
  • 242