Leak in NSScanner category method

Posted by jluckyiv on Stack Overflow See other posts from Stack Overflow or by jluckyiv
Published on 2010-03-17T13:20:44Z Indexed on 2010/03/17 21:01 UTC
Read the original article Hit count: 294

I created an NSScanner category method that shows a leak in instruments.


- (BOOL)scanBetweenPrefix:(NSString *)prefix 
                andSuffix:(NSString *)suffix 
               intoString:(NSString **)value
{
    NSCharacterSet *charactersToBeSkipped = [self charactersToBeSkipped];
    [self setCharactersToBeSkipped:nil];

    BOOL result = NO;

    // find the prefix; the scanString method below fails if you don't do this
    if (![self scanUpToString:prefix intoString:nil])
    {
        MY_LOG(@"Prefix %@ is missing.", prefix);
        return result;
    }

    //scan the prefix and discard
    [self scanString:prefix intoString:nil];

    // scan the important part and save it
    if ([self scanUpToString:suffix intoString:value]) // this line leaks
    {
        result = YES;
    }
    [self setCharactersToBeSkipped:charactersToBeSkipped];
    return result;
}

I figure it's the way I'm passing the value to/from the method, but I'm not sure. It's a small leak (32 bytes), but I'd like to do this right if I can. Thanks in advance.

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about objective-c