diff --git a/src/ccl_fftlog.c b/src/ccl_fftlog.c index 5efd1765a..4c72db055 100644 --- a/src/ccl_fftlog.c +++ b/src/ccl_fftlog.c @@ -208,7 +208,7 @@ static void fht(int npk, int N, double dim, double mu, double q, double kcrc, int noring, double complex* u, int *status) { - fftw_plan forward_plan, reverse_plan; + fftw_plan forward_plan = NULL, reverse_plan = NULL; double L = log(k[N-1]/k[0]) * N/(N-1.); double complex* ulocal = NULL; if(u == NULL) { @@ -225,8 +225,8 @@ static void fht(int npk, int N, } } - fftw_complex* a_tmp; - fftw_complex* b_tmp; + fftw_complex* a_tmp = NULL; + fftw_complex* b_tmp = NULL; if(*status == 0) { a_tmp = fftw_alloc_complex(N); if(a_tmp==NULL) @@ -336,10 +336,8 @@ static void fht(int npk, int N, } //end omp parallel } - if(*status == 0) { - fftw_destroy_plan(forward_plan); - fftw_destroy_plan(reverse_plan); - } + if(forward_plan != NULL) fftw_destroy_plan(forward_plan); + if(reverse_plan != NULL) fftw_destroy_plan(reverse_plan); free(ulocal); //TODO: free this up @@ -347,7 +345,7 @@ static void fht(int npk, int N, fftw_free(b_tmp); } -/* Compute the discrete Hankel transform of the function a(r) +/* Compute the discrete Hankel transform of the function a(r) * weighted by a power law and the nth derivative of the * (spherical) bessel function. Explicitly, this function computes * \tilde{a}(k)= \int \frac{dr}{(xk)^plaw} a(r) (J/j)^(n)_\mu(xk) @@ -369,11 +367,11 @@ static void general_fht(int npk, int N, kcrc = mu+1.0; mu = mu+0.5*spherical_bessel; - fftw_plan forward_plan, reverse_plan; + fftw_plan forward_plan = NULL, reverse_plan = NULL; double L = log(k[N-1]/k[0]) * N/(N-1.); double complex* ulocal = NULL; if(u == NULL) { - + kcrc = goodkr_new_deriv(N, mu, q, L, spherical_bessel, bessel_deriv,plaw, kcrc); ulocal = malloc (sizeof(complex double)*N); @@ -386,8 +384,8 @@ static void general_fht(int npk, int N, } } - fftw_complex* a_tmp; - fftw_complex* b_tmp; + fftw_complex* a_tmp = NULL; + fftw_complex* b_tmp = NULL; if(*status == 0) { a_tmp = fftw_alloc_complex(N); if(a_tmp==NULL) @@ -500,10 +498,8 @@ static void general_fht(int npk, int N, } //end omp parallel } - if(*status == 0) { - fftw_destroy_plan(forward_plan); - fftw_destroy_plan(reverse_plan); - } + if(forward_plan != NULL) fftw_destroy_plan(forward_plan); + if(reverse_plan != NULL) fftw_destroy_plan(reverse_plan); free(ulocal); //TODO: free this up diff --git a/src/ccl_power.c b/src/ccl_power.c index 709887b32..970aa8134 100644 --- a/src/ccl_power.c +++ b/src/ccl_power.c @@ -129,10 +129,12 @@ static ccl_f2d_t *ccl_compute_linpower_analytic(ccl_cosmology* cosmo, void* par, y2d[j] += log_sigma8; } + // Free the first spline unconditionally; re-allocate with normalisation only on success. + // Without this, ccl_sigma8 failure above would leak the first psp_out. + ccl_f2d_t_free(psp_out); + psp_out = NULL; + if(*status==0) { - // Free the previous P(k,a) spline, and allocate a new one to store the - // properly-normalized P(k,a) - ccl_f2d_t_free(psp_out); psp_out = ccl_f2d_t_new(na,z,nk,x,y2d,NULL,NULL,0, 1,2,ccl_f2d_cclgrowth,1,0,2, ccl_f2d_3,status);