From 37e1b9523b89c5fe029df46ac7db1ef02b76a652 Mon Sep 17 00:00:00 2001
From: Robbert van der Helm <mail@robbertvanderhelm.nl>
Date: Tue, 8 Mar 2022 00:46:04 +0100
Subject: [PATCH] Optionally disallow allocations in reset function

---
 src/wrapper/clap/wrapper.rs | 6 +++---
 src/wrapper/vst3/wrapper.rs | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/wrapper/clap/wrapper.rs b/src/wrapper/clap/wrapper.rs
index 89a39103..22b513dd 100644
--- a/src/wrapper/clap/wrapper.rs
+++ b/src/wrapper/clap/wrapper.rs
@@ -728,7 +728,7 @@ impl<P: ClapPlugin> Wrapper<P> {
             &mut wrapper.make_process_context(Transport::new(buffer_config.sample_rate)),
         ) {
             // As per-the trait docs we'll always call this after the initialization function
-            plugin.reset();
+            process_wrapper(|| plugin.reset());
 
             // Preallocate enough room in the output slices vector so we can convert a `*mut *mut
             // f32` to a `&mut [&mut f32]` in the process call
@@ -774,7 +774,7 @@ impl<P: ClapPlugin> Wrapper<P> {
         check_null_ptr!((), plugin);
         let wrapper = &*(plugin as *const Self);
 
-        wrapper.plugin.write().reset();
+        process_wrapper(|| wrapper.plugin.write().reset());
     }
 
     unsafe extern "C" fn process(
@@ -1655,7 +1655,7 @@ impl<P: ClapPlugin> Wrapper<P> {
                 &buffer_config,
                 &mut wrapper.make_process_context(Transport::new(buffer_config.sample_rate)),
             );
-            plugin.reset();
+            process_wrapper(|| plugin.reset());
         }
 
         true
diff --git a/src/wrapper/vst3/wrapper.rs b/src/wrapper/vst3/wrapper.rs
index 92c8505c..430efd7e 100644
--- a/src/wrapper/vst3/wrapper.rs
+++ b/src/wrapper/vst3/wrapper.rs
@@ -242,7 +242,7 @@ impl<P: Vst3Plugin> IComponent for Wrapper<P> {
                     .inner
                     .make_process_context(Transport::new(buffer_config.sample_rate)),
             );
-            plugin.reset();
+            process_wrapper(|| plugin.reset());
         }
 
         kResultOk
@@ -602,7 +602,7 @@ impl<P: Vst3Plugin> IAudioProcessor for Wrapper<P> {
                 .make_process_context(Transport::new(buffer_config.sample_rate)),
         ) {
             // As per-the trait docs we'll always call this after the initialization function
-            plugin.reset();
+            process_wrapper(|| plugin.reset());
 
             // Preallocate enough room in the output slices vector so we can convert a `*mut *mut
             // f32` to a `&mut [&mut f32]` in the process call