commit 141e6beb06d328bd0d8bfd984dd9127628141174
parent 91ba833642c3740636c3f718d539ba19099801f6
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 25 Jun 2020 16:10:38 +0200
Fix a possible memory leak in sdis_solve_medium[_green_function]
Diffstat:
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/sdis_solve_medium_Xd.h b/src/sdis_solve_medium_Xd.h
@@ -336,7 +336,10 @@ XD(solve_medium)
* function. Simply takes 0 as relative time */
time = 0;
res_local = green_function_create_path(greens[ithread], &green_path);
- if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; }
+ if(res_local != RES_OK) {
+ ATOMIC_SET(&res, res_local);
+ goto error_it;
+ }
pgreen_path = &green_path;
}
@@ -348,7 +351,7 @@ XD(solve_medium)
if(res_local != RES_OK) {
log_err(scn->dev, "%s: could not sample a medium position.\n", FUNC_NAME);
ATOMIC_SET(&res, res_local);
- continue;
+ goto error_it;
}
/* Run a probe realisation */
@@ -359,7 +362,7 @@ XD(solve_medium)
if(res_simul != RES_OK && res_simul != RES_BAD_OP) {
ATOMIC_SET(&res, res_simul);
- continue;
+ goto error_it;
}
/* Finalize the registered path */
@@ -371,10 +374,15 @@ XD(solve_medium)
/* Check if the path must be saved regarding the register_paths mask */
if(!(register_paths & (int)pheat_path->status)) {
heat_path_release(pheat_path);
+ pheat_path = NULL;
} else { /* Register the sampled path */
res_local = estimator_add_and_release_heat_path(estimator, pheat_path);
- if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; }
+ if(res_local != RES_OK) {
+ ATOMIC_SET(&res, res_local);
+ goto error_it;
+ }
}
+ pheat_path = NULL;
}
/* Stop time registration */
@@ -395,6 +403,11 @@ XD(solve_medium)
progress = pcent;
log_info(scn->dev, "Solving medium temperature: %3d%%\r", progress);
}
+ exit_it:
+ if(pheat_path) heat_path_release(pheat_path);
+ continue;
+ error_it:
+ goto exit_it;
}
if(res != RES_OK) goto error;
diff --git a/src/test_sdis_solve_medium.c b/src/test_sdis_solve_medium.c
@@ -390,6 +390,18 @@ main(int argc, char** argv)
OK(sdis_estimator_ref_put(estimator));
solve_args.medium = solid1;
+
+ /* Check simulation error handling when paths are registered */
+ solve_args.nrealisations = 10;
+ solve_args.register_paths = SDIS_HEAT_PATH_ALL;
+ fluid_param->temperature = -1;
+ BA(sdis_solve_medium(scn, &solve_args, &estimator));
+ fluid_param->temperature = Tf1;
+ OK(sdis_solve_medium(scn, &solve_args, &estimator));
+ OK(sdis_estimator_ref_put(estimator));
+ solve_args.nrealisations = N;
+ solve_args.register_paths = SDIS_HEAT_PATH_NONE;
+
OK(sdis_solve_medium(scn, &solve_args, &estimator));
OK(sdis_estimator_get_realisation_count(estimator, &nreals));
OK(sdis_estimator_get_failure_count(estimator, &nfails));