compiled schema BUGFIX proper default freeing on type error
Fixes #1004
diff --git a/src/tree_schema_compile.c b/src/tree_schema_compile.c
index add51fe..fa71dac 100644
--- a/src/tree_schema_compile.c
+++ b/src/tree_schema_compile.c
@@ -3869,6 +3869,14 @@
/* the dflts member is just filled to avoid getting the default value from the type */
llist->dflts = (void*)llist_p->dflts;
ret = lys_compile_node_type(ctx, node_p, &llist_p->type, (struct lysc_node_leaf*)llist);
+ if (ret != LY_SUCCESS) {
+ /* make sure the defaults are freed correctly */
+ if (llist_p->dflts) {
+ llist->dflts = NULL;
+ }
+ return ret;
+ }
+
if (llist_p->dflts) {
llist->dflts = NULL; /* reset the temporary llist_p->dflts */
LY_ARRAY_CREATE_GOTO(ctx->ctx, llist->dflts_mods, LY_ARRAY_SIZE(llist_p->dflts), ret, done);