- (BOOL)parserJSONString:(NSString *)jsonString error:(NSError **)anError {
//some data getting
//error handle
NSString *description = @"phone number couldn't be using";
NSString *recoverySuggestion = @"Please provide an other phone number.";
NSInteger errorCode = -1;
NSArray *keys = [NSArray arrayWithObjects: NSLocalizedDescriptionKey, NSLocalizedRecoverySuggestionErrorKey, nil];
NSArray *values = [NSArray arrayWithObjects:description, recoverySuggestion, nil];
NSDictionary *userDict = [NSDictionary dictionaryWithObjects:values forKeys:keys];
*anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict];
return NO;
}
*anError = [[NSError alloc] initWithDomain:@"my domain" code:errorCode userInfo:userDict]; compiler give next leak warning
“Potential null dereference. According to coding standards in ‘Creating and Returning NSError Objects’ the parameter ” may be null”
How to fix this?
This is not actually a leak warning, but a potential dereference of a null pointer. The compiler is complaining about the line
You assign to the location being pointed to by
anErrorwithout checking, whetheranErroris actually the null pointer (which is allowed “according to the coding standard”, and may happen, if the caller is not interested in detailed error information).