简体   繁体   中英

An obvious leak but clang static analyzer didnot detect, Why?

I wrote some code like this,

- (NSString*) caleSignParam:(NSMutableArray*)postData
{
    NSMutableArray* keyArray = [[NSMutableArray alloc] initWithCapacity:50];

    ......
    NSArray* sortedKeys = [keyArray sortedArrayUsingComparator:
                       (NSComparator)^(NSString *obj1, NSString *obj2) {
                           return [obj1 compare:obj2 options:NSLiteralSearch];
                       }];
    ......


    NSString* signStr = aString;

    return signStr;
}

I forgot to release keyArray, and using non-ARC, but when I click "Analyze" on the menu of Xcode, it didnot detect the leak of keyArray.

If I comment the line of "NSArray *sortedKeys = ...", It can detect the leak of keyArray.

I wonder what's wrong with static analyzer.

I really appreciate your help.

It's important to understand that static analyzer is not always correct, nor it is always incorrect. It can throw false positives and false negatives. However default settings make it so that chances of false positive are minimal. In this particular case I would guess that analyzer did not have enough data to make a definite decision of what happens with keyArray

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM