Skip to content
Snippets Groups Projects
Commit f9892322 authored by Botond Baranyi's avatar Botond Baranyi
Browse files

Fixed memory leak in union JSON decoder


Change-Id: Ic49a0b3d8c72c9eff0d5ce2c16b753aa425d84f4
Signed-off-by: default avatarBotond Baranyi <botond.baranyi@ericsson.com>
parent 064072f0
No related branches found
No related tags found
No related merge requests found
......@@ -2307,7 +2307,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
" }\n"
" return ret_val;\n");
if (!sdef->jsonAsValue) {
src = mputprintf(src,
src = mputstr(src,
" }\n"
" else {\n" // if there is no 'as value' set in the type descriptor
" size_t dec_len = p_tok.get_next_token(&j_token, NULL, NULL);\n"
......@@ -2324,9 +2324,7 @@ void defUnionClass(struct_def const *sdef, output_struct *output)
" if (JSON_TOKEN_NAME != j_token) {\n"
" JSON_ERROR(TTCN_EncDec::ET_INVAL_MSG, JSON_DEC_NAME_TOKEN_ERROR);\n"
" return JSON_ERROR_FATAL;\n"
" } else {\n"
" union_selection = %s;\n "
, unbound_value);
" } else {\n");
for (i = 0; i < sdef->nElements; ++i) {
src = mputprintf(src,
"if (%d == name_len && 0 == strncmp(fld_name, \"%s\", name_len)) {\n"
......
......@@ -279,6 +279,9 @@ external function f_dec_R(in octetstring x) return R
external function f_dec_A(in octetstring x) return A
with { extension "prototype(convert)"; extension "decode(JSON)"; }
external function f_dec_A_fast(in octetstring x, out A y)
with { extension "prototype(fast)"; extension "decode(JSON)"; }
external function f_dec_ER(in octetstring x) return EmptyRec
with { extension "prototype(convert)"; extension "decode(JSON)"; }
......
......@@ -506,6 +506,9 @@ testcase tc_union2() runs on MTC{
var octetstring os := char2oct("{\"f\":\"infinity\"}");
f_check_encoding(encoded:= f_enc_A(myunion), expected := os)
f_bool2verdict(match(f_dec_A(f_enc_A(myunion)), myunion));
var A myunion2 := { b := false };
f_dec_A_fast(f_enc_A(myunion), myunion2);
f_bool2verdict(match(myunion2, myunion));
}
testcase tc_union_false() runs on MTC{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment