From 30959cf1c9f023a243de697c5ec7a34a3d33f803 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sat, 11 Jun 2016 18:50:57 +0000 Subject: [PATCH] Clean up some memory leaks Move the FFTW3 cleanup into the main routine as it should only be called once rather than every time the settings configuration is changed or reset (MultiSettings). Call the new fini_ldpc_ routine before exiting in the main routine to free the LDPC resources. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6764 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- main.cpp | 21 +++++++++++++++++++++ mainwindow.cpp | 12 ------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index a8bf174b1..cfc320447 100644 --- a/main.cpp +++ b/main.cpp @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -36,6 +37,12 @@ #include "Radio.hpp" #include "FrequencyList.hpp" +extern "C" { + // Fortran procedures we need + void four2a_(_Complex float *, int * nfft, int * ndim, int * isign, int * iform, int len); + void fini_ldpc_ (); +} + namespace { struct RNGSetup @@ -293,6 +300,20 @@ int main(int argc, char *argv[]) result = a.exec(); } while (!result && !multi_settings.exit ()); + + // clean up lazily initialized resources + { + int nfft {-1}; + int ndim {1}; + int isign {1}; + int iform {1}; + // free FFT plan resources + four2a_ (nullptr, &nfft, &ndim, &isign, &iform, 0); + } + fftwf_forget_wisdom (); + fftwf_cleanup (); + fini_ldpc_ (); // free LDPC decoder resources + temp_dir.removeRecursively (); // clean up temp files return result; } diff --git a/mainwindow.cpp b/mainwindow.cpp index 76a16999c..20d372809 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -63,8 +63,6 @@ extern "C" { void symspec_(struct dec_data *, int* k, int* ntrperiod, int* nsps, int* ingain, int* minw, float* px, float s[], float* df3, int* nhsym, int* npts8); - void four2a_(_Complex float *, int * nfft, int * ndim, int * isign, int * iform, int len); - void hspec_(short int d2[], int* k, int* ingain, float green[], float s[], int* jh); void gen4_(char* msg, int* ichk, char* msgsent, int itone[], @@ -832,16 +830,6 @@ MainWindow::~MainWindow() QString fname {QDir::toNativeSeparators(m_dataDir.absoluteFilePath ("wsjtx_wisdom.dat"))}; QByteArray cfname=fname.toLocal8Bit(); fftwf_export_wisdom_to_filename(cfname); - { - int nfft {-1}; - int ndim {1}; - int isign {1}; - int iform {1}; - // free FFT plan resources - four2a_ (nullptr, &nfft, &ndim, &isign, &iform, 0); - } - fftwf_forget_wisdom (); - fftwf_cleanup (); m_audioThread.quit (); m_audioThread.wait (); }