13
0

Fix crashes when unloading mac VST2 plugins

CFBundleRef is reference counted, so we need to retain
a reference. Previously it went out of scope at the end
of mac_vst_load().
This commit is contained in:
Robin Gareus 2021-06-28 15:44:09 +02:00
parent 5e54425a35
commit b01fe8b0e4
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 20 additions and 15 deletions

View File

@ -25,6 +25,10 @@
#include "ardour/libardour_visibility.h"
#include "ardour/vestige/vestige.h"
#ifdef MACVST_SUPPORT
#include <Carbon/Carbon.h>
#endif
struct LIBARDOUR_API _VSTKey
{
/** virtual-key code, or 0 if this _VSTFXKey is a `character' key */
@ -62,16 +66,17 @@ typedef AEffect * (* main_entry_t) (audioMasterCallback);
struct LIBARDOUR_API _VSTHandle
{
void* dll;
#ifdef MACVST_SUPPORT
CFBundleRef bundleRef;
CFBundleRefNum res_file_id;
#else
void* dll;
#endif
char* name;
char* path;
main_entry_t main_entry;
int plugincnt;
#ifdef MACVST_SUPPORT
int32_t res_file_id;
#endif
};
typedef struct _VSTHandle VSTHandle;

View File

@ -97,33 +97,33 @@ mac_vst_load (const char *path)
fhandle = mac_vst_handle_new ();
fhandle->dll = NULL;
fhandle->bundleRef = 0;
CFURLRef url;
if (!(url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*)path, (CFIndex) strlen (path), true))) {
return 0;
}
CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
fhandle->bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
CFRelease (url);
if (bundleRef == 0) {
if (fhandle->bundleRef == 0) {
return 0;
}
if (!CFBundleLoadExecutable (bundleRef)) {
CFRelease (bundleRef);
if (!CFBundleLoadExecutable (fhandle->bundleRef)) {
CFRelease (fhandle->bundleRef);
return 0;
}
fhandle->name = strdup (path);
fhandle->dll = (void*) &bundleRef;
fhandle->main_entry = (main_entry_t)
CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
CFBundleGetFunctionPointerForName (fhandle->bundleRef, CFSTR("main_macho"));
if (!fhandle->main_entry) {
fhandle->main_entry = (main_entry_t)
CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
CFBundleGetFunctionPointerForName (fhandle->bundleRef, CFSTR("VSTPluginMain"));
}
if (fhandle->main_entry == 0) {
@ -131,7 +131,7 @@ mac_vst_load (const char *path)
return 0;
}
fhandle->res_file_id = CFBundleOpenBundleResourceMap (bundleRef);
fhandle->res_file_id = CFBundleOpenBundleResourceMap (fhandle->bundleRef);
/*return the handle of the plugin*/
return fhandle;
@ -150,7 +150,7 @@ mac_vst_unload (VSTHandle* fhandle)
/*Valid plugin loaded?*/
if (fhandle->dll)
if (fhandle->bundleRef)
{
CFBundleRef* bundleRefPtr = (CFBundleRef*) fhandle->dll;
CFBundleCloseBundleResourceMap (*bundleRefPtr, (CFBundleRefNum)fhandle->res_file_id);