NSString potential leak

When I build and analyze my project on XCode, I obtain a 'warning' on the following line:

NSString *contactEmail = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0);

The message is: Potential leak on object allocated on line ... and stored into contactEmail.

Is there any error on that line?


I get the same 'warning' with this line of code:

ABMultiValueRef emailInfo = ABRecordCopyValue(person, kABPersonEmailProperty);

But here, I can't do this:

[emailInfo release];

I'm developing for iPhone.


ABMultiValueCopyValueAtIndex is a "Copy" function, which follows the "Create Rule". You need to call CFRelease to release it after finish using it.

NSString *contactEmail = (NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0);
if (contactEmail != nil)
  CFRelease((CFTypeRef) contactEmail);

  1. The cast is somewhat pointless.
  2. The line might leak, unless you release or autorelease it somewhere.

Edit: For brevity:

NSString *contactEmail = [(NSString *)ABMultiValueCopyValueAtIndex(emailInfo, 0) autorelease];

(The cast might still be pointless, I'm unsure as to how the compiler would handle trying sending a message directly to a CFTypeRef.)

Need Your Help

Public access local IIS server

asp.net iis iis-7 iis-6

I have an ASP.NET application which uses the local IIS server.

Node.js Express sessions using connect-redis with Unix Domain Sockets

node.js session express redis unix-socket

I am trying to utilize a Redis-based session store using connect-redis, communicating over UNIX Domain Sockets.