Clang static analyzer warning "Null pointer argument when calling CFRelease"

In Xcode 4.6, the clang static parser warns me about "null pointer argument when calling CFRelease".

Here is a screenshot of the analyzer warning:

Clang Static Analyzer Warning

And here is the code if you want to copy and paste it:

- (void)test
{
    CFUUIDRef aUUID = CFUUIDCreate(kCFAllocatorDefault);
    [self setUUID:aUUID];
    CFRelease(aUUID);
}

- (void)setUUID:(CFUUIDRef)uuid
{
    _uuid = uuid ? CFRetain(uuid) : CFUUIDCreate(kCFAllocatorDefault);
}

      

I don't understand why this is warning me. aUUID

can never be a null pointer, can it? I have learned to distrust myself rather than the tools I use, so I ask here. I would be very glad if someone could explain to me what I am missing.

+3


source to share


1 answer


Anything that returns an allocated value could theoretically return NULL.

The parser follows several possible execution paths. When the "aUUID is NULL" script is executed, it eventually ends up in a CFRelease of a NULL object.



This is not what setUUID

is the reason, but only the path where the problem was found, so the illustrated path.

0


source







All Articles