AFAIK, yes. 

Please file a bug to add to the ones I have filed on this and similar behaviors.

On Jan 13, 2010, at 9:49 PM, cocoa-dev-requ...@lists.apple.com wrote:

> Message: 10
> Date: Thu, 14 Jan 2010 12:54:46 +1100
> From: Graham Cox <graham....@bigpond.com>
> Subject: Analyzer in error?
> To: Cocoa-Dev List <cocoa-dev@lists.apple.com>
> Message-ID: <de12774f-4249-44b3-b108-e6b2e5212...@bigpond.com>
> Content-Type: text/plain; charset=us-ascii
> 
> Hi all, I have the following code in a category on NSData:
> 
> 
> @implementation NSData (SHA1Hash)
> 
> - (NSData*)   sha1Hash
> {
>       // calculates the 160 bit SHA-1 digest of the given data
>       
>       unsigned char* digest = (unsigned char*) malloc(20);
>       SHA1([self bytes], [self length], digest);
>       
>       return [[self class] dataWithBytesNoCopy:digest length:20];
> }
> 
> 
> @end
> 
> 
> The static analyzer reports this:
> 
>       Potential leak of an object allocated on line 622
> 
>               Method returns an Objective-C object with a +1 retain count 
> (owning reference)
>               Object returned to caller as an owning reference (single retain 
> count transferred to caller)
>               Object allocated on line 622 is returned from a method whose 
> name ('sha1Hash') does not contain 'copy' or otherwise starts with 'new' or 
> 'alloc'.  This violates                the naming convention rules given in 
> the Memory Management Guide for Cocoa (object leaked)
> 
> But I think this is wrong - [NSData dataWithBytesNoCopy] returns an object I 
> don't own, and it in turn takes ownership of <digest>. So where's the leak? 
> Is clang simply mistaking the fact that +dataWithBytesNoCopy CONTAINS 'copy' 
> and not STARTS WITH copy?
> 
> --Graham
> 

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to