commit 37eb4c0832b34afa3664f91f1605a57b47430c2e
parent a45661fb8b75a5f95c452dc1a80630f7871d253d
Author: falkTX <falktx@falktx.com>
Date: Sat, 18 Sep 2021 13:32:50 +0100
VST2: Cleanup created objects on module/dll unload
Signed-off-by: falkTX <falktx@falktx.com>
Diffstat:
1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp
@@ -42,6 +42,7 @@
#define VST_FORCE_DEPRECATED 0
#include <clocale>
+#include <list>
#include <map>
#include <string>
@@ -1635,6 +1636,20 @@ static void vst_processReplacingCallback(AEffect* effect, float** inputs, float*
#undef validPlugin
#undef vstObjectPtr
+static struct Cleanup {
+ std::list<AEffect*> effects;
+
+ ~Cleanup()
+ {
+ for (std::list<AEffect*>::iterator it = effects.begin(), end = effects.end(); it != end; ++it)
+ {
+ AEffect* const effect = *it;
+ delete (VstObject*)effect->object;
+ delete effect;
+ }
+ }
+} sCleanup;
+
// -----------------------------------------------------------------------
END_NAMESPACE_DISTRHO
@@ -1714,12 +1729,13 @@ const AEffect* VSTPluginMain(audioMasterCallback audioMaster)
effect->processReplacing = vst_processReplacingCallback;
// pointers
- VstObject* const obj(new VstObject());
+ VstObject* const obj = new VstObject();
obj->audioMaster = audioMaster;
obj->plugin = nullptr;
// done
effect->object = obj;
+ sCleanup.effects.push_back(effect);
return effect;
}