stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit ea9cb71f99a816e9f4cf4299b91a6dc29d1b603f
parent 2165778bb3d2569da5225d20002b1b1c3cef7935
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 12 Feb 2021 16:51:32 +0100

Fix a memleak in camera parsing

Diffstat:
Msrc/stardis-parsing.c | 135+++++++++++++++++++++++++++++++++++++++++--------------------------------------
1 file changed, 70 insertions(+), 65 deletions(-)

diff --git a/src/stardis-parsing.c b/src/stardis-parsing.c @@ -952,86 +952,91 @@ parse_camera char** opt = NULL; struct camera* cam; struct str keep; + int i = 0; res_T res = RES_OK; ASSERT(cam_param && stardis); cam = &stardis->camera; line = split_line(cam_param, ':'); - str_init(stardis->allocator, &keep); + if(!line) { + res = RES_MEM_ERR; + goto error; + } - if(line) { - int i = 0; - for(i = 0; *(line + i); i++) { - size_t len = 0; - ERR(str_set(&keep, line[i])); - opt = split_line(line[i], '='); - if(!opt[0] || ! opt[1] || opt[2]) { - if(res == RES_OK) res = RES_BAD_ARG; - logger_print((logger), LOG_ERROR, - "Invalid option syntax: %s\n", str_cget(&keep)); - goto error; - } - ERR(str_set(&keep, opt[0])); - if(strcasecmp(opt[0], "T") == 0) { - GET_OPTIONAL_TIME_RANGE(opt[1], 0, cam->time_range, logger, "%s", - str_cget(&keep)); - } - else if(strcasecmp(opt[0], "FILE") == 0) { - ERR(str_set(&cam->file_name, opt[1])); - } - else if(strcasecmp(opt[0], "FMT") == 0) { - if(strcasecmp(opt[1], "VTK") == 0) - cam->fmt = STARDIS_RENDERING_OUTPUT_FILE_FMT_VTK; - else if(strcasecmp(opt[1], "HT") == 0) - cam->fmt = STARDIS_RENDERING_OUTPUT_FILE_FMT_HT; - else { - logger_print(logger, LOG_ERROR, - "Unexpected value for rendering option %s: %s.\n", - opt[0], opt[1]); - res = RES_BAD_ARG; - goto error; - } - } - else if(strcasecmp(opt[0], "FOV") == 0) { - ERR(cstr_to_double(opt[1], &cam->fov)); - } - else if(strcasecmp(opt[0], "UP") == 0) { - ERR(cstr_to_list_double(opt[1], ',', cam->up, &len, 3)); - } - else if(strcasecmp(opt[0], "TGT") == 0) { - ERR(cstr_to_list_double(opt[1], ',', cam->tgt, &len, 3)); - cam->auto_look_at = 0; - } - else if(strcasecmp(opt[0], "POS") == 0) { - ERR(cstr_to_list_double(opt[1], ',', cam->pos, &len, 3)); - cam->auto_look_at = 0; - } - else if(strcasecmp(opt[0], "IMG") == 0) { - unsigned img_sz[2]; - ERR(cstr_to_list_uint(opt[1], 'x', img_sz, &len, 2)); - cam->img_width = img_sz[0]; - cam->img_height = img_sz[1]; - } - else if(strcasecmp(opt[0], "SPP") == 0) { - ERR(cstr_to_uint(opt[1], &cam->spp)); - } else { + str_init(stardis->allocator, &keep); + for(i = 0; *(line + i); i++) { + size_t len = 0; + ERR(str_set(&keep, line[i])); + opt = split_line(line[i], '='); + if(!opt[0] || !opt[1] || opt[2]) { /* We expect 2 parts */ + if(res == RES_OK) res = RES_BAD_ARG; + logger_print((logger), LOG_ERROR, + "Invalid option syntax: %s\n", str_cget(&keep)); + goto error; + } + if(strcasecmp(opt[0], "T") == 0) { + GET_OPTIONAL_TIME_RANGE(opt[1], 0, cam->time_range, logger, "%s", opt[0]); + } + else if(strcasecmp(opt[0], "FILE") == 0) { + ERR(str_set(&cam->file_name, opt[1])); + } + else if(strcasecmp(opt[0], "FMT") == 0) { + if(strcasecmp(opt[1], "VTK") == 0) + cam->fmt = STARDIS_RENDERING_OUTPUT_FILE_FMT_VTK; + else if(strcasecmp(opt[1], "HT") == 0) + cam->fmt = STARDIS_RENDERING_OUTPUT_FILE_FMT_HT; + else { logger_print(logger, LOG_ERROR, - "Unexpected option for rendering mode: %s.\n", - opt[0]); + "Unexpected value for rendering option %s: %s.\n", + opt[0], opt[1]); res = RES_BAD_ARG; goto error; } } - } + else if(strcasecmp(opt[0], "FOV") == 0) { + ERR(cstr_to_double(opt[1], &cam->fov)); + } + else if(strcasecmp(opt[0], "UP") == 0) { + ERR(cstr_to_list_double(opt[1], ',', cam->up, &len, 3)); + } + else if(strcasecmp(opt[0], "TGT") == 0) { + ERR(cstr_to_list_double(opt[1], ',', cam->tgt, &len, 3)); + cam->auto_look_at = 0; + } + else if(strcasecmp(opt[0], "POS") == 0) { + ERR(cstr_to_list_double(opt[1], ',', cam->pos, &len, 3)); + cam->auto_look_at = 0; + } + else if(strcasecmp(opt[0], "IMG") == 0) { + unsigned img_sz[2]; + ERR(cstr_to_list_uint(opt[1], 'x', img_sz, &len, 2)); + cam->img_width = img_sz[0]; + cam->img_height = img_sz[1]; + } + else if(strcasecmp(opt[0], "SPP") == 0) { + ERR(cstr_to_uint(opt[1], &cam->spp)); + } else { + logger_print(logger, LOG_ERROR, + "Unexpected option for rendering mode: %s.\n", + opt[0]); + res = RES_BAD_ARG; + goto error; + } -end: -#define FREE_AARRAY(ARRAY) if(ARRAY) {\ - int i = 0; \ - for(i=0; *(ARRAY+i);i++){\ - free(ARRAY[i]);\ +#define FREE_AARRAY(ARRAY) \ +if(ARRAY) {\ + int i__ = 0; \ + for(i__=0; *((ARRAY)+i__);i__++){\ + free((ARRAY)[i__]);\ }\ free(ARRAY);\ + (ARRAY) = NULL;\ } + + FREE_AARRAY(opt) + } + +end: FREE_AARRAY(line) FREE_AARRAY(opt) #undef FREE_AARRAY