parser yang BUGFIX parsing path in type statement
Added deletion from dictionary in case of error.
diff --git a/src/parser_yang.c b/src/parser_yang.c
index 0880269..4c76d43 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -2150,9 +2150,16 @@
return LY_EVALID;
}
- LY_CHECK_RET(parse_text_field(ctx, LY_STMT_PATH, 0, &str_path, Y_STR_ARG, &type->exts));
+ /* Usually, in the parser_yang.c, the result of the parsing is stored directly in the
+ * corresponding structure, so in case of failure, the lysp_module_free function will take
+ * care of removing the parsed value from the dictionary. But in this case, it is not possible
+ * to rely on lysp_module_free because the result of the parsing is stored in a local variable.
+ */
+ LY_CHECK_ERR_RET(ret = parse_text_field(ctx, LY_STMT_PATH, 0, &str_path, Y_STR_ARG, &type->exts),
+ lydict_remove(PARSER_CTX(ctx), str_path), ret);
ret = ly_path_parse(PARSER_CTX(ctx), NULL, str_path, 0, LY_PATH_BEGIN_EITHER, LY_PATH_LREF_TRUE,
LY_PATH_PREFIX_OPTIONAL, LY_PATH_PRED_LEAFREF, &type->path);
+ /* Moreover, even if successful, the string is removed from the dictionary. */
lydict_remove(PARSER_CTX(ctx), str_path);
LY_CHECK_RET(ret);
type->flags |= LYS_SET_PATH;
diff --git a/tests/utests/schema/test_parser_yang.c b/tests/utests/schema/test_parser_yang.c
index 5f29c27..d226bc3 100644
--- a/tests/utests/schema/test_parser_yang.c
+++ b/tests/utests/schema/test_parser_yang.c
@@ -1053,6 +1053,11 @@
assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
CHECK_LOG_CTX("Missing mandatory keyword \"type\" as a child of \"leaf\".", "Line number 1.");
lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
+
+ in.current = "l { type iid { path qpud wrong {";
+ assert_int_equal(LY_EVALID, parse_leaf(YCTX, NULL, (struct lysp_node **)&l));
+ CHECK_LOG_CTX("Invalid character sequence \"wrong\", expected a keyword.", "Line number 1.");
+ lysp_node_free(YCTX->parsed_mod->mod->ctx, (struct lysp_node *)l); l = NULL;
}
static void