stardis-solver

Solve coupled heat transfers
git clone git://git.meso-star.fr/stardis-solver.git
Log | Files | Refs | README | LICENSE

commit 4653a5b7c1eaa9773391b13d8b0eb5fa972ba077
parent 31dc31181fb81409484328cdc21fd3d2a03cf3b2
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Thu, 25 Jun 2020 11:50:47 +0200

Fix a possible memory leak in sdis_solve_boundary[_green_function]

Diffstat:
Msrc/sdis_solve_boundary_Xd.h | 24++++++++++++++++++++----
Msrc/sdis_solve_probe_Xd.h | 2++
Msrc/test_sdis_solve_boundary.c | 5+++++
3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/sdis_solve_boundary_Xd.h b/src/sdis_solve_boundary_Xd.h @@ -267,7 +267,10 @@ XD(solve_boundary) * 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; } @@ -288,7 +291,10 @@ XD(solve_boundary) &prim, st); d2_set_f2(uv, st); #endif - if(res_local != RES_OK) { ATOMIC_SET(&res, res_local); continue; } + if(res_local != RES_OK) { + ATOMIC_SET(&res, res_local); + goto error_it; + } /* Map from boundary scene to sdis scene */ ASSERT(prim.prim_id < args->nprimitives); @@ -303,7 +309,7 @@ XD(solve_boundary) /* Fatal error */ if(res_simul != RES_OK && res_simul != RES_BAD_OP) { ATOMIC_SET(&res, res_simul); - continue; + goto error_it; } /* Register heat path */ @@ -315,9 +321,14 @@ XD(solve_boundary) /* 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; } } @@ -339,6 +350,11 @@ XD(solve_boundary) progress = pcent; log_info(scn->dev, "Solving boundary 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/sdis_solve_probe_Xd.h b/src/sdis_solve_probe_Xd.h @@ -190,12 +190,14 @@ XD(solve_probe) /* 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); goto error_it; } + pheat_path = NULL; } } diff --git a/src/test_sdis_solve_boundary.c b/src/test_sdis_solve_boundary.c @@ -478,6 +478,11 @@ main(int argc, char** argv) /* Dump path */ bound_args.nrealisations = N_dump; bound_args.register_paths = SDIS_HEAT_PATH_ALL; + + /* Check simulation error handling when paths are registered */ + fluid_param->temperature = UNKNOWN_TEMPERATURE; + BA(SOLVE(box_scn, &bound_args, &estimator)); + fluid_param->temperature = Tf; OK(SOLVE(box_scn, &bound_args, &estimator)); dump_heat_paths(fp, estimator); OK(sdis_estimator_ref_put(estimator));