From 9c279564146bef08d2cd1da7141a0e88ec2a01ff Mon Sep 17 00:00:00 2001 From: Tobias Doerffel Date: Wed, 30 Apr 2014 15:20:44 +0200 Subject: [PATCH] ZynAddSubFX: allocate spectrum on heap instead of stack When loading some presets the PADnoteParameters spectrum size is 524288 or even bigger resulting in a stack allocation of 2 MB or more. This results in a stack overflow on Win32 and thus crashes LMMS. Fix this by allocating the spectrum on the heap instead. Closes #543. --- plugins/zynaddsubfx/src/Params/PADnoteParameters.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/zynaddsubfx/src/Params/PADnoteParameters.cpp b/plugins/zynaddsubfx/src/Params/PADnoteParameters.cpp index 94599e72f..a44da25ab 100644 --- a/plugins/zynaddsubfx/src/Params/PADnoteParameters.cpp +++ b/plugins/zynaddsubfx/src/Params/PADnoteParameters.cpp @@ -555,7 +555,7 @@ void PADnoteParameters::applyparameters(bool lockmutex) { const int samplesize = (((int) 1) << (Pquality.samplesize + 14)); int spectrumsize = samplesize / 2; - REALTYPE spectrum[spectrumsize]; + REALTYPE *spectrum = new REALTYPE[spectrumsize]; int profilesize = 512; REALTYPE profile[profilesize]; @@ -653,6 +653,8 @@ void PADnoteParameters::applyparameters(bool lockmutex) delete (fft); deleteFFTFREQS(&fftfreqs); + delete[] spectrum; + //delete the additional samples that might exists and are not useful if(lockmutex) { pthread_mutex_lock(mutex);