From 033b8bb21104909e01c9a696ea65ab28904afebc Mon Sep 17 00:00:00 2001 From: Chris Date: Wed, 19 Jun 2024 12:29:02 +0200 Subject: [PATCH] fix memory leak --- oversampling/oversampler.h | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/oversampling/oversampler.h b/oversampling/oversampler.h index f5af0e3..14946a5 100644 --- a/oversampling/oversampler.h +++ b/oversampling/oversampler.h @@ -15,6 +15,8 @@ public: buffer[1].reserve(num_samples); } + ~oversampler() { delete[] ptrs; } + void init(double _samplerate, int _ratio) { samplerate = _samplerate * _ratio; @@ -65,7 +67,10 @@ public: } } - return get_pointers(); + ptrs[0] = buffer[0].data(); + ptrs[1] = buffer[1].data(); + + return ptrs; } void downsample(float** _outputs) @@ -97,14 +102,6 @@ private: chebyshev lowpass_out2 {samplerate, 20000}; std::array, 2> buffer; - - float** get_pointers() - { - float** ptrs = new float*[2]; - ptrs[0] = buffer[0].data(); - ptrs[1] = buffer[1].data(); - - return ptrs; - } + float** ptrs = new float*[2]; }; } // namespace trnr \ No newline at end of file