Objective C: Why is this code leaking?

Posted by Johnny Grass on Stack Overflow See other posts from Stack Overflow or by Johnny Grass
Published on 2011-01-10T02:46:41Z Indexed on 2011/01/10 2:53 UTC
Read the original article Hit count: 176

Filed under:
|

I'm trying to implement a method similar to what mytunescontroller uses to check if it has been added to the app's login items. This code compiles without warnings but if I run the leaks performance tool I get the following leaks:

Leaked Object  #    Address Size    Responsible Library Responsible Frame
NSURL          7    < multiple >    448 LaunchServices  LSSharedFileListItemGetFSRef
NSCFString     6    < multiple >    432 LaunchServices  LSSharedFileListItemGetFSRef

Here is the responsible culprit:

- (BOOL)isAppStartingOnLogin 
{
    LSSharedFileListRef loginListRef = LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
    if (loginListRef) {
        NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginListRef, NULL);
        NSURL *itemURL;
        for (id itemRef in loginItemsArray) {           
            if (LSSharedFileListItemResolve((LSSharedFileListItemRef)itemRef, 0, (CFURLRef *) &itemURL, NULL) == noErr) {
                if ([[itemURL path] hasPrefix:[[NSBundle mainBundle] bundlePath]]) {
                    [loginItemsArray release];
                    CFRelease(loginListRef);
                        return YES;
                 }
             }
        }

    [loginItemsArray release];
    CFRelease(loginListRef);

    }

    return NO;
}

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about memory-leaks