commit 828ab9a8363d2c46d6e156cb2225d39b9b344e43
parent 5570c9f9a9cc0d42eca81ceaf5899db2e58ac918
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 25 Jun 2020 10:32:58 +0200
Fix a possible memory leak in sdis_solve_probe[_green_function]
Diffstat:
3 files changed, 26 insertions(+), 10 deletions(-)
diff --git a/src/sdis_solve_probe_Xd.h b/src/sdis_solve_probe_Xd.h
@@ -164,8 +164,10 @@ XD(solve_probe)
* 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;
}
@@ -177,7 +179,7 @@ XD(solve_probe)
/* Handle fatal error */
if(res_simul != RES_OK && res_simul != RES_BAD_OP) {
ATOMIC_SET(&res, res_simul);
- continue;
+ goto error_it;
}
if(pheat_path) {
@@ -190,7 +192,10 @@ XD(solve_probe)
heat_path_release(pheat_path);
} 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;
+ }
}
}
@@ -212,6 +217,11 @@ XD(solve_probe)
progress = pcent;
log_info(scn->dev, "Solving probe 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_boundary_Xd.h b/src/sdis_solve_probe_boundary_Xd.h
@@ -201,7 +201,7 @@ XD(solve_probe_boundary)
res_local = green_function_create_path(greens[ithread], &green_path);
if(res_local != RES_OK) {
ATOMIC_SET(&res, res_local);
- goto realisation_error;
+ goto error_it;
}
pgreen_path = &green_path;
}
@@ -213,7 +213,7 @@ XD(solve_probe_boundary)
/* Handle fatal error */
if(res_simul != RES_OK && res_simul != RES_BAD_OP) {
ATOMIC_SET(&res, res_simul);
- goto realisation_error;
+ goto error_it;
}
if(pheat_path) {
@@ -230,7 +230,7 @@ XD(solve_probe_boundary)
res_local = estimator_add_and_release_heat_path(estimator, pheat_path);
if(res_local != RES_OK) {
ATOMIC_SET(&res, res_local);
- goto realisation_error;
+ goto error_it;
}
pheat_path = NULL;
}
@@ -255,11 +255,11 @@ XD(solve_probe_boundary)
log_info(scn->dev, "Solving probe boundary temperature: %3d%%\r", progress);
}
- realisation_exit:
+ exit_it:
if(pheat_path) heat_path_release(pheat_path);
continue;
- realisation_error:
- goto realisation_exit;
+ error_it:
+ goto exit_it;
}
if(res != RES_OK) goto error;
diff --git a/src/test_sdis_solve_probe.c b/src/test_sdis_solve_probe.c
@@ -451,6 +451,12 @@ main(int argc, char** argv)
solve_args.nrealisations = N_dump;
solve_args.register_paths = SDIS_HEAT_PATH_ALL;
+
+ /* Check simulation error handling when paths are registered */
+ fluid_param->temperature = -1;
+ BA(sdis_solve_probe(scn, &solve_args, &estimator));
+
+ fluid_param->temperature = 300;
OK(sdis_solve_probe(scn, &solve_args, &estimator));
OK(sdis_estimator_get_paths_count(estimator, &n));
CHK(n == N_dump);