From 37eb4c0832b34afa3664f91f1605a57b47430c2e Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 18 Sep 2021 13:33:17 +0100 Subject: [PATCH] VST2: Cleanup created objects on module/dll unload Signed-off-by: falkTX --- distrho/src/DistrhoPluginVST2.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/distrho/src/DistrhoPluginVST2.cpp b/distrho/src/DistrhoPluginVST2.cpp index e8af1507..35ed3d1e 100644 --- a/distrho/src/DistrhoPluginVST2.cpp +++ b/distrho/src/DistrhoPluginVST2.cpp @@ -42,6 +42,7 @@ #define VST_FORCE_DEPRECATED 0 #include +#include #include #include @@ -1635,6 +1636,20 @@ static void vst_processReplacingCallback(AEffect* effect, float** inputs, float* #undef validPlugin #undef vstObjectPtr +static struct Cleanup { + std::list effects; + + ~Cleanup() + { + for (std::list::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; }