lib: Mac: add missing dlclose()

This commit is contained in:
Charlie Fenton 2017-07-11 07:24:35 -07:00
parent c5d2062230
commit 5d9df2de45
1 changed files with 4 additions and 1 deletions

View File

@ -71,7 +71,7 @@ OSStatus GetPathToAppFromID(OSType creator, CFStringRef bundleID, char *path, si
// LSCopyApplicationURLsForBundleIdentifier is not available before OS 10.10 // LSCopyApplicationURLsForBundleIdentifier is not available before OS 10.10
CFArrayRef (*LSCopyAppURLsForBundleID)(CFStringRef, CFErrorRef) = NULL; CFArrayRef (*LSCopyAppURLsForBundleID)(CFStringRef, CFErrorRef) = NULL;
void *LSlib = dlopen("/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices", RTLD_NOW); void *LSlib = dlopen("/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/LaunchServices", RTLD_NOW | RTLD_NODELETE);
if (LSlib) { if (LSlib) {
LSCopyAppURLsForBundleID = (CFArrayRef(*)(CFStringRef, CFErrorRef)) dlsym(LSlib, "LSCopyApplicationURLsForBundleIdentifier"); LSCopyAppURLsForBundleID = (CFArrayRef(*)(CFStringRef, CFErrorRef)) dlsym(LSlib, "LSCopyApplicationURLsForBundleIdentifier");
} }
@ -88,6 +88,7 @@ OSStatus GetPathToAppFromID(OSType creator, CFStringRef bundleID, char *path, si
dlsym(LSlib, "LSFindApplicationForInfo"); dlsym(LSlib, "LSFindApplicationForInfo");
} }
if (LSFindAppForInfo == NULL) { if (LSFindAppForInfo == NULL) {
if (LSlib) dlclose(LSlib);
return fnfErr; return fnfErr;
} }
err = (*LSFindAppForInfo)(creator, bundleID, NULL, NULL, &appURL); err = (*LSFindAppForInfo)(creator, bundleID, NULL, NULL, &appURL);
@ -105,6 +106,7 @@ OSStatus GetPathToAppFromID(OSType creator, CFStringRef bundleID, char *path, si
} }
} }
if (err != noErr) { if (err != noErr) {
if (LSlib) dlclose(LSlib);
return err; return err;
} }
} // end if (LSCopyApplicationURLsForBundleIdentifier != NULL) } // end if (LSCopyApplicationURLsForBundleIdentifier != NULL)
@ -117,6 +119,7 @@ OSStatus GetPathToAppFromID(OSType creator, CFStringRef bundleID, char *path, si
if (appURL) { if (appURL) {
CFRelease(appURL); CFRelease(appURL);
} }
if (LSlib) dlclose(LSlib);
return err; return err;
} }