NSCFString leak inVolving NSString
- by Srilakshmi Manthena
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;
}