prevent a huge memory leak by calling fftw3 in a loop
This commit is contained in:
parent
1f7d84b270
commit
598b72be37
|
|
@ -160,15 +160,21 @@ com_fft(wordlist *wl)
|
|||
printf("FFT: Time span: %g s, input length: %d\n", span, length);
|
||||
printf("FFT: Frequency resolution: %g Hz, output length: %d\n", 1.0/span, fpts);
|
||||
|
||||
in = fftw_malloc(sizeof(double) * (unsigned int) length);
|
||||
out = fftw_malloc(sizeof(fftw_complex) * (unsigned int) fpts);
|
||||
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[0][j]*win[j];
|
||||
|
||||
/* data have same type and length - so we need only one plan */
|
||||
plan_forward = fftw_plan_dft_r2c_1d(length, in, out, FFTW_ESTIMATE);
|
||||
|
||||
for (i = 0; i<ngood; i++) {
|
||||
|
||||
in = fftw_malloc(sizeof(double) * (unsigned int) length);
|
||||
out = fftw_malloc(sizeof(fftw_complex) * (unsigned int) fpts);
|
||||
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[i][j]*win[j];
|
||||
|
||||
plan_forward = fftw_plan_dft_r2c_1d(length, in, out, FFTW_ESTIMATE);
|
||||
if (i > 0) {
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[i][j]*win[j];
|
||||
}
|
||||
|
||||
fftw_execute(plan_forward);
|
||||
|
||||
|
|
@ -178,8 +184,12 @@ com_fft(wordlist *wl)
|
|||
fdvec[i][j].cx_imag = out[j][1]/scale;
|
||||
}
|
||||
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
}
|
||||
|
||||
fftw_destroy_plan(plan_forward);
|
||||
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
|
||||
#else /* Green's FFT */
|
||||
|
||||
|
|
@ -213,14 +223,11 @@ com_fft(wordlist *wl)
|
|||
|
||||
tfree(in);
|
||||
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
done:
|
||||
#ifdef HAVE_LIBFFTW3
|
||||
fftw_destroy_plan(plan_forward);
|
||||
#endif
|
||||
|
||||
done:
|
||||
tfree(tdvec);
|
||||
tfree(fdvec);
|
||||
tfree(win);
|
||||
|
|
@ -385,12 +392,18 @@ com_psd(wordlist *wl)
|
|||
in = fftw_malloc(sizeof(double) * (unsigned int) length);
|
||||
out = fftw_malloc(sizeof(fftw_complex) * (unsigned int) fpts);
|
||||
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[0][j]*win[j];
|
||||
|
||||
/* data have same type and length - so we need only one plan */
|
||||
plan_forward = fftw_plan_dft_r2c_1d(length, in, out, FFTW_ESTIMATE);
|
||||
|
||||
for (i = 0; i<ngood; i++) {
|
||||
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[i][j]*win[j];
|
||||
|
||||
plan_forward = fftw_plan_dft_r2c_1d(length, in, out, FFTW_ESTIMATE);
|
||||
if (i > 0) {
|
||||
for (j = 0; j < length; j++)
|
||||
in[j] = tdvec[i][j]*win[j];
|
||||
}
|
||||
|
||||
fftw_execute(plan_forward);
|
||||
|
||||
|
|
@ -479,12 +492,12 @@ com_psd(wordlist *wl)
|
|||
fdvec[i][j].cx_real = reald[j] * (double)fpts / freq[fpts - 1];
|
||||
}
|
||||
|
||||
done:
|
||||
#ifdef HAVE_LIBFFTW3
|
||||
fftw_destroy_plan(plan_forward);
|
||||
fftw_free(in);
|
||||
fftw_free(out);
|
||||
fftw_destroy_plan(plan_forward);
|
||||
#endif
|
||||
done:
|
||||
tfree(tdvec);
|
||||
tfree(fdvec);
|
||||
tfree(win);
|
||||
|
|
|
|||
Loading…
Reference in New Issue