NSCFString leak inVolving NSString

Posted by Srilakshmi Manthena on Stack Overflow See other posts from Stack Overflow or by Srilakshmi Manthena
Published on 2010-03-23T07:10:53Z Indexed on 2010/03/23 7:13 UTC
Read the original article Hit count: 296

Filed under:

Hi, I am getting leak at

      NSString *firstNameStr = [NSString stringWithFormat:@"%s",firstNameString];

CODE:

+(NSString *)getValueForProperty:(ABPropertyID)propertyId forContact:(NSString *)contactId 

{ if (addressBook == nil) { addressBook = ABAddressBookCreate(); } ABRecordID contactIntId = [contactId intValue]; ABRecordRef person = ABAddressBookGetPersonWithRecordID(addressBook, contactIntId);

CFStringRef firstName; char *firstNameString; firstName = ABRecordCopyValue(person, propertyId);

// Paso a char* los datos para que se puedan escribir static char* fallback = ""; int fbLength = strlen(fallback);

int firstNameLength = fbLength; bool firstNameFallback = true;

if (firstName != NULL) { firstNameLength = (int) CFStringGetLength(firstName); firstNameFallback = false; }

if (firstNameLength == 0) { firstNameLength = fbLength; firstNameFallback = true; }

firstNameString = malloc(sizeof(char)*(firstNameLength+1));

if (firstNameFallback == true) { strcpy(firstNameString, fallback); } else { CFStringGetCString(firstName, firstNameString, 10*CFStringGetLength(firstName), kCFStringEncodingASCII); }

if (firstName != NULL) { CFRelease(firstName); }

NSString *firstNameStr = [NSString stringWithFormat:@"%s",firstNameString];

free(firstNameString);

return firstNameStr;

   }

© Stack Overflow or respective owner

Related posts about objective-c