I received a couple of crash reports from users running Mac OS X 10.6.6. My app crashes with the error below:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000060443800
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Application Specific Information:
objc_msgSend() selector name: release
Thread 0 Crashed: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x97d98edb objc_msgSend + 27
1 com.apple.LaunchServices 0x9038dc62 __LSSharedFileListItemDeallocate + 126
2 com.apple.CoreFoundation 0x9489d101 _CFRelease + 353
3 com.apple.CoreFoundation 0x948c75b2 __CFArrayReleaseValues + 210
4 com.apple.CoreFoundation 0x9489d101 _CFRelease + 353
5 ...myapp.AppName 0x00005d67 +[ABTools isLoginItem] + 1597
The code that breaks is trying to determine if the application has installed a login item. The 3rd to last line releasing the array fails (on 10.6.6, works on 10.5.8).
Can anybody see why that would happen? I looked at that code for way too long and I don't see it.
Thanks! Mark
+ (BOOL) isLoginItem {
BOOL isLoginItem = NO;
UInt32 seedValue;
NSString *appName = [NSString stringWithFormat:@"%@.app", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"]];
NSString *appPath = [[NSBundle mainBundle] bundlePath];
LSSharedFileListRef loginItems = LSSharedFileListCreate(NULL,kLSSharedFileListSessionLoginItems,NULL);
if (!loginItems) {
return isLoginItem;
}
CFURLRef url = (CFURLRef)[NSURL fileURLWithPath:appPath];
NSArray *loginItemsArray = (NSArray *)LSSharedFileListCopySnapshot(loginItems, &seedValue);
if (!loginItemsArray) {
return isLoginItem;
}
for (id item in loginItemsArray)
{
if (LSSharedFileListItemResolve((LSSharedFileListItemRef)item,0,(CFURLRef*)&url,NULL) == noErr
&& [[(NSURL *)url path] isEqualToString:appPath]) {
isLoginItem = YES;
}
if (url) CFRelease(url);
}
if (loginItemsArray) [loginItemsArray release]; // THIS FAILS ON Mac OS X 10.6.6
if (loginItems) CFRelease(loginItems);
return isLoginItem;
}
Not sure about the problem that you are having, but I have used this code for my app and it is working perfectly Enabling launch on startup