I just ran into an issue with the XCode static code analyzer of XCode 3.2. It shows me a potential leak which I find is not justified. I just want to check with other people and make sure it really is a false positive.
Here is the main code (in some function body):
NSError *error = nil;
NSData *urlData = /* ... */;
NSXMLDocument *doc = [[NSXMLDocument alloc] initWithData:urlData options:0 error:&error];
if (![self validateObject:doc withError:error]) {
return;
}
// ...
[doc release];
Here is the validate method called above:
- (BOOL)validateObject:(id)object withError:(NSError *)error {
if (!object) {
// do something meaningful...
return NO;
} else {
return YES;
}
}
XCode tells me that the allocation of doc is a potential leak as the validate method could return NO and release would not be sent to doc. But as a matter of fact, if the initialization fails, nil is returned by initWithData:options: and no harm is caused. The docs even state this.
So, what do the experts say? False positive or not?
Best, Harald