schiff

Estimate the radiative properties of soft particless
git clone git://git.meso-star.com/schiff.git
Log | Files | Refs | README | LICENSE

commit d7664dc5eddafad289885d973f91feccc9e89204
parent 6ea4d621d7292919597b79382b21ea846e7abbed
Author: Vincent Forest <vincent.forest@meso-star.com>
Date:   Wed,  6 Apr 2016 11:52:00 +0200

Fix memory leaks on parsing error

A memory leak occurred when an error is detected during the parsing of a
geometry with an histogram distribution of at least one of its
parameter. The geometry type is now setup at the beginning of its
parsing in order to correctly release its attribute when an error
occurs.

Diffstat:
Msrc/schiff_args.c | 27+++++++++++++++++++++++++--
1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/src/schiff_args.c b/src/schiff_args.c @@ -651,6 +651,11 @@ parse_yaml_ellipsoid res_T res = RES_OK; ASSERT(filename && doc && node && geom && geom_proba); +/* Setup the type at the beginning in order to define what arguments should + * be released if a parsing error occurs. Note that one can define the main + * type or its "equivalent sphere" variation. */ + geom->type = SCHIFF_ELLIPSOID; + if(node->type != YAML_MAPPING_NODE) { log_err(filename, node, "expecting a mapping of ellipsoid attributes.\n"); return RES_BAD_ARG; @@ -769,6 +774,11 @@ parse_yaml_cylinder res_T res = RES_OK; ASSERT(filename && doc && node && geom && geom_proba); + /* Setup the type at the beginning in order to define what arguments should + * be released if a parsing error occurs. Note that one can define the main + * type or its "equivalent sphere" variation. */ + geom->type = SCHIFF_CYLINDER; + if(node->type != YAML_MAPPING_NODE) { log_err(filename, node, "expecting a mapping of cylinder attributes.\n"); return RES_BAD_ARG; @@ -888,6 +898,11 @@ parse_yaml_helical_pipe res_T res = RES_OK; ASSERT(filename && doc && node && geom && geom_proba); + /* Setup the type at the beginning in order to define what arguments should + * be released if a parsing error occurs. Note that one can define the main + * type or its "equivalent sphere" variation. */ + geom->type = SCHIFF_HELICAL_PIPE; + if(node->type != YAML_MAPPING_NODE) { log_err(filename, node, "expecting a mapping of helical pipe attributes.\n"); return RES_BAD_ARG; @@ -1033,6 +1048,10 @@ parse_yaml_sphere res_T res = RES_OK; ASSERT(filename && doc && node && geom && geom_proba); + /* Setup the type at the beginning in order to define what arguments should + * be released if a parsing error occurs. */ + geom->type = SCHIFF_SPHERE; + if(node->type != YAML_MAPPING_NODE) { log_err(filename, node, "expecting a mapping of sphere attributes.\n"); return RES_BAD_ARG; @@ -1096,7 +1115,6 @@ parse_yaml_sphere if(!(mask & SLICES)) { /* Default number of slices */ geom->data.sphere.nslices = SCHIFF_SPHERE_DEFAULT.nslices; } - geom->type = SCHIFF_SPHERE; return RES_OK; } @@ -1121,6 +1139,11 @@ parse_yaml_supershape res_T res = RES_OK; ASSERT(filename && doc && node && geom && geom_proba); + /* Setup the type at the beginning in order to define what arguments should + * be released if a parsing error occurs. Note that one can define the main + * type or its "equivalent sphere" variation. */ + geom->type = SCHIFF_SUPERSHAPE; + if(node->type != YAML_MAPPING_NODE) { log_err(filename, node, "expecting a mapping of supershape attributes.\n"); return RES_BAD_ARG; @@ -1165,7 +1188,7 @@ parse_yaml_supershape /* Equivalent sphere radius */ } else if(!strcmp((char*)key->data.scalar.value, "radius_sphere")) { SETUP_MASK(RADIUS_SPHERE, "equivalent sphere radius of the supershape"); - res = parse_yaml_param_distribution(filename, doc, val, DBL_MIN, DBL_MAX, + res = parse_yaml_param_distribution(filename, doc, val, DBL_MIN, DBL_MAX, &geom->data.supershape.radius_sphere); /* # slices used to discretized the super shape */