Skip to content

Commit 0d2f3cf

Browse files
Fix Group B memory bugs (issues #74, #55) and Group A headers (issue #84)
- Fix delete→free in Morlet::getWavelet() for malloc-allocated memory - Fix memory leak: free lastscalemem with _aligned_free/_aligned_malloc on Windows, free/aligned_alloc on POSIX - Add missing <cassert> include (issue #84) - Also fix indentation in convolve() else branch Co-Authored-By: Oz <oz-agent@warp.dev>
1 parent 49cb5a9 commit 0d2f3cf

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

src/fcwt/fcwt.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ limitations under the License.
3737
*/
3838

3939
#include "fcwt.h"
40+
#include <cassert>
4041

4142
Morlet::Morlet(float bandwidth) {
4243
four_wavelen = 0.9876f;
@@ -100,8 +101,8 @@ void Morlet::getWavelet(float scale, complex<float>* pwav, int pn) {
100101
pwav[t].imag(imag[t]);
101102
}
102103

103-
delete real;
104-
delete imag;
104+
free(real);
105+
free(imag);
105106
};
106107

107108
//==============================================================//
@@ -403,9 +404,15 @@ void FCWT::convolve(fftwf_plan p, fftwf_complex *Ihat, fftwf_complex *O1, comple
403404
#endif
404405
memset(lastscalemem,0,sizeof(fftwf_complex)*newsize);
405406

406-
fftbased(p, Ihat, O1, (float*)lastscalemem, wav->mother, newsize, scale, wav->imag_frequency, wav->doublesided);
407+
fftbased(p, Ihat, O1, (float*)lastscalemem, wav->mother, newsize, scale,
408+
wav->imag_frequency, wav->doublesided);
407409
if(use_normalization) fft_normalize((complex<float>*)lastscalemem, newsize);
408410
memcpy(out, (complex<float>*)lastscalemem, sizeof(complex<float>)*size);
411+
#ifdef _WIN32
412+
_aligned_free(lastscalemem);
413+
#else
414+
free(lastscalemem);
415+
#endif
409416
} else {
410417
if(!out) {
411418
std::cout << "OUT NOT A POINTER" << std::endl;

0 commit comments

Comments
 (0)