mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
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:
@@ -86,10 +86,10 @@ Vst3PluginBridge::Vst3PluginBridge()
|
|||||||
Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
||||||
// Even though we're working with raw pointers here, we should pretend that
|
// Even though we're working with raw pointers here, we should pretend that
|
||||||
// we're `IPtr<Steinberg::IPluginFactory>` and do the reference counting
|
// we're `IPtr<Steinberg::IPluginFactory>` and do the reference counting
|
||||||
// ourselves because you can't always safely pass those around The VST3
|
// ourselves. This should work the same was as the standard implementation
|
||||||
// interface can't pass smart pointers around because of binary
|
// in `public.sdk/source/main/pluginfactory.h`. If we were to use an IPtr or
|
||||||
// compatibility, so we'll have to do the reference counting by hand like in
|
// an STL smart pointer we would get a double free (or rather, a use after
|
||||||
// the implementation in `public.sdk/source/main/pluginfactory.h`.
|
// free).
|
||||||
if (plugin_factory) {
|
if (plugin_factory) {
|
||||||
plugin_factory->addRef();
|
plugin_factory->addRef();
|
||||||
} else {
|
} else {
|
||||||
@@ -97,11 +97,11 @@ Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
|||||||
// will request after loading the module. Host callback handlers should
|
// will request after loading the module. Host callback handlers should
|
||||||
// have started before this since the Wine plugin host will request a
|
// have started before this since the Wine plugin host will request a
|
||||||
// copy of the configuration during its initialization.
|
// 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(
|
sockets.host_vst_control.receive_into(
|
||||||
WantsPluginFactory{}, *plugin_factory,
|
WantsPluginFactory{}, *plugin_factory,
|
||||||
std::pair<Vst3Logger&, bool>(logger, true));
|
std::pair<Vst3Logger&, bool>(logger, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
return plugin_factory.get();
|
return plugin_factory;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,11 +80,11 @@ class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
|||||||
* Our plugin factory. All information about the plugin and its supported
|
* Our plugin factory. All information about the plugin and its supported
|
||||||
* classes are copied directly from the Windows VST3 plugin's factory on the
|
* classes are copied directly from the Windows VST3 plugin's factory on the
|
||||||
* Wine side, and we'll provide an implementation that can send control
|
* Wine side, and we'll provide an implementation that can send control
|
||||||
* messages to the Wine plugin host. The VST3 interface only passes raw
|
* messages to the Wine plugin host. As explained in `get_plugin_factory()`,
|
||||||
* pointers around and the receiving side should then use `IPtr<T>::adopt()`
|
* this cannot be a smart pointer because the factory is supposed to free
|
||||||
* or `owned()` to get back the orignal smart pointer.
|
* itself when the host removes its last adopted `IPtr<IpluginFactory>`.
|
||||||
*
|
*
|
||||||
* @related get_plugin_factory
|
* @related get_plugin_factory
|
||||||
*/
|
*/
|
||||||
Steinberg::IPtr<YaPluginFactory> plugin_factory;
|
YaPluginFactory* plugin_factory;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -38,9 +38,6 @@ bool InitModule() {
|
|||||||
assert(bridge == nullptr);
|
assert(bridge == nullptr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// This is the only place where we have to use manual memory management.
|
|
||||||
// The bridge's destructor is called when the `effClose` opcode is
|
|
||||||
// received.
|
|
||||||
bridge = new Vst3PluginBridge();
|
bridge = new Vst3PluginBridge();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user