Use raw pointers for the plugin factory

Since the object cleans up after itself after the smart pointers are
dropped on the host side this would result in a use after free by the
smart pointers.
This commit is contained in:
Robbert van der Helm
2020-12-07 18:23:04 +01:00
parent d79bc3b936
commit 7b3a6af7d1
3 changed files with 10 additions and 13 deletions
+6 -6
View File
@@ -86,10 +86,10 @@ Vst3PluginBridge::Vst3PluginBridge()
Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
// Even though we're working with raw pointers here, we should pretend that
// we're `IPtr<Steinberg::IPluginFactory>` and do the reference counting
// ourselves because you can't always safely pass those around The VST3
// interface can't pass smart pointers around because of binary
// compatibility, so we'll have to do the reference counting by hand like in
// the implementation in `public.sdk/source/main/pluginfactory.h`.
// ourselves. This should work the same was as the standard implementation
// in `public.sdk/source/main/pluginfactory.h`. If we were to use an IPtr or
// an STL smart pointer we would get a double free (or rather, a use after
// free).
if (plugin_factory) {
plugin_factory->addRef();
} else {
@@ -97,11 +97,11 @@ Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
// will request after loading the module. Host callback handlers should
// have started before this since the Wine plugin host will request a
// copy of the configuration during its initialization.
plugin_factory = Steinberg::owned(new YaPluginFactoryPluginImpl(*this));
plugin_factory = new YaPluginFactoryPluginImpl(*this);
sockets.host_vst_control.receive_into(
WantsPluginFactory{}, *plugin_factory,
std::pair<Vst3Logger&, bool>(logger, true));
}
return plugin_factory.get();
return plugin_factory;
}