path FEATURE duplicate value types in predicates
To avoid problems with the order of freeing
the type itself and then the predicate.
diff --git a/src/path.c b/src/path.c
index 0ec1d02..f590fbc 100644
--- a/src/path.c
+++ b/src/path.c
@@ -509,6 +509,9 @@
LYD_HINT_DATA, key, NULL, LY_VLOG_LYSC, key));
++(*tok_idx);
+ /* "allocate" the type to avoid problems when freeing the value after the type was freed */
+ ++((struct lysc_type *)p->value.realtype)->refcount;
+
/* ']' */
assert(expr->tokens[*tok_idx] == LYXP_TOKEN_BRACK2);
++(*tok_idx);
@@ -553,6 +556,9 @@
LYD_HINT_DATA, ctx_node, NULL, LY_VLOG_LYSC, ctx_node));
++(*tok_idx);
+ /* "allocate" the type to avoid problems when freeing the value after the type was freed */
+ ++((struct lysc_type *)p->value.realtype)->refcount;
+
/* ']' */
assert(expr->tokens[*tok_idx] == LYXP_TOKEN_BRACK2);
++(*tok_idx);
@@ -973,6 +979,7 @@
/* key-predicate or leaf-list-predicate */
(*dup)[u].predicates[v].key = pred->key;
pred->value.realtype->plugin->duplicate(ctx, &pred->value, &(*dup)[u].predicates[v].value);
+ ++((struct lysc_type *)pred->value.realtype)->refcount;
break;
case LY_PATH_PREDTYPE_NONE:
break;
@@ -1001,7 +1008,10 @@
break;
case LY_PATH_PREDTYPE_LIST:
case LY_PATH_PREDTYPE_LEAFLIST:
- predicates[u].value.realtype->plugin->free(ctx, &predicates[u].value);
+ if (predicates[u].value.realtype) {
+ predicates[u].value.realtype->plugin->free(ctx, &predicates[u].value);
+ lysc_type_free((struct ly_ctx *)ctx, (struct lysc_type *)predicates[u].value.realtype);
+ }
break;
}
}