LSSTDESC / CCL

DESC Core Cosmology Library: cosmology routines with validated numerical accuracy
BSD 3-Clause "New" or "Revised" License
144 stars 65 forks source link

memory leaks in redshift space correlation function #568

Closed beckermr closed 5 years ago

beckermr commented 5 years ago

It appears we have more memory leaks in the redshift space correlation function computations.

Blocks of code like this

  xi_arr = malloc(sizeof(double) * N_ARR);
  if (xi_arr == NULL) {
    free(k_arr);
    free(pk_arr);
    free(s_arr);
    *status = CCL_ERROR_MEMORY;
    strcpy(cosmo->status_message,
           "ccl_correlation.c: ccl_correlation_multipole ran out of memory\n");
    return;
  }
  xi_arr0 = malloc(sizeof(double) * N_ARR);
  if (xi_arr0 == NULL) {
    free(k_arr);
    free(pk_arr);
    free(s_arr);
    *status = CCL_ERROR_MEMORY;
    strcpy(cosmo->status_message,
           "ccl_correlation.c: ccl_correlation_multipole ran out of memory\n");
    return;
  }
tmcclintock commented 5 years ago

This block could use the same treatment that parts of background.c received -- consolidating the deallocation at the end of the function and having a single return. This would eliminate the pattern of: if(error){free;return;} statement if(error){free;return;} statement ...