Skip to content

Commit

Permalink
Re #7876. Fix potential memory leak.
Browse files Browse the repository at this point in the history
Don't leak memory if one of the 3 allocations failed.
  • Loading branch information
RussellTaylor committed Sep 4, 2013
1 parent 14fedf7 commit 4953b37
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Code/Mantid/MantidPlot/src/FFT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,15 @@ QString FFT::fftTable()
gsl_fft_complex_wavetable *wavetable = gsl_fft_complex_wavetable_alloc (d_n);
gsl_fft_complex_workspace *workspace = gsl_fft_complex_workspace_alloc (d_n);

if(!amp || !wavetable || !workspace){
QMessageBox::critical(dynamic_cast<ApplicationWindow *>(parent()), tr("MantidPlot") + " - " + tr("Error"),
tr("Could not allocate memory, operation aborted!"));
d_init_err = true;
return "";
if(!amp || !wavetable || !workspace)
{
QMessageBox::critical(dynamic_cast<ApplicationWindow *>(parent()), tr("MantidPlot") + " - " + tr("Error"),
tr("Could not allocate memory, operation aborted!"));
delete[] amp;
if (wavetable) gsl_fft_complex_wavetable_free (wavetable);
if (workspace) gsl_fft_complex_workspace_free (workspace);
d_init_err = true;
return "";
}

double df = 1.0/(double)(d_n*d_sampling);//frequency sampling
Expand Down

0 comments on commit 4953b37

Please sign in to comment.