Valgrind fixes

This commit is contained in:
Olof hagsand 2023-09-28 17:31:14 +02:00
parent 520f20def5
commit 794a17c2bb
5 changed files with 32 additions and 17 deletions

View file

@ -48,6 +48,7 @@ struct clixon_json_yacc {
cxobj *jy_current; /* cxobj active element (changes with parse context) */
cxobj **jy_xvec; /* Vector of created top-level nodes (to know which are created) */
int jy_xlen; /* Length of jy_xvec */
cbuf *jy_cbuf_str; /* cbuf used for strings, if error needs to be deallocated */
};
typedef struct clixon_json_yacc clixon_json_yacc;

View file

@ -156,6 +156,8 @@ clixon_json_parseerror(void *_jy,
_JY->jy_linenum ,
s,
clixon_json_parsetext);
if (_JY->jy_cbuf_str)
cbuf_free(_JY->jy_cbuf_str);
return;
}
@ -282,7 +284,7 @@ value : J_TRUE { json_current_body(_JY, "true"); _PARSE_DEBUG("va
| object { _PARSE_DEBUG("value->object"); }
| array { _PARSE_DEBUG("value->array"); }
| number { json_current_body(_JY, $1); free($1); _PARSE_DEBUG("value->number");}
| string { json_current_body(_JY, cbuf_get($1)); cbuf_free($1); _PARSE_DEBUG("value->string");}
| string { json_current_body(_JY, cbuf_get($1)); cbuf_free($1); _JY->jy_cbuf_str = NULL; _PARSE_DEBUG("value->string");}
;
@ -294,7 +296,7 @@ objlist : pair { _PARSE_DEBUG("objlist->pair");}
| objlist ',' pair { _PARSE_DEBUG("objlist->objlist , pair");}
;
pair : string { json_current_new(_JY, cbuf_get($1));cbuf_free($1);} ':'
pair : string { json_current_new(_JY, cbuf_get($1));cbuf_free($1); _JY->jy_cbuf_str = NULL;} ':'
value { json_current_pop(_JY);}{ _PARSE_DEBUG("pair->string : value");}
;
@ -320,6 +322,7 @@ ustring : ustring J_STRING
| J_STRING
{
cbuf *cb = cbuf_new();
_JY->jy_cbuf_str = cb;
cbuf_append_str(cb,$1);
$$=cb;
}