path REFACTOR nodes are not needed when freeing predicate values
Also solves problem of freeing order between the
path and the referenced nodes.
diff --git a/src/path.c b/src/path.c
index 0552e66..0ec1d02 100644
--- a/src/path.c
+++ b/src/path.c
@@ -525,7 +525,7 @@
/* names (keys) are unique - it was checked when parsing */
LOGVAL_P(ctx, cur_node, LYVE_XPATH, "Predicate missing for a key of %s \"%s\" in path.",
lys_nodetype2str(ctx_node->nodetype), ctx_node->name);
- ly_path_predicates_free(ctx, LY_PATH_PREDTYPE_LIST, NULL, *predicates);
+ ly_path_predicates_free(ctx, LY_PATH_PREDTYPE_LIST, *predicates);
*predicates = NULL;
return LY_EVALID;
}
@@ -985,8 +985,7 @@
}
void
-ly_path_predicates_free(const struct ly_ctx *ctx, enum ly_path_pred_type pred_type, const struct lysc_node *llist,
- struct ly_path_predicate *predicates)
+ly_path_predicates_free(const struct ly_ctx *ctx, enum ly_path_pred_type pred_type, struct ly_path_predicate *predicates)
{
LY_ARRAY_COUNT_TYPE u;
@@ -1001,10 +1000,8 @@
/* nothing to free */
break;
case LY_PATH_PREDTYPE_LIST:
- ((struct lysc_node_leaf *)predicates[u].key)->type->plugin->free(ctx, &predicates[u].value);
- break;
case LY_PATH_PREDTYPE_LEAFLIST:
- ((struct lysc_node_leaflist *)llist)->type->plugin->free(ctx, &predicates[u].value);
+ predicates[u].value.realtype->plugin->free(ctx, &predicates[u].value);
break;
}
}
@@ -1017,7 +1014,7 @@
LY_ARRAY_COUNT_TYPE u;
LY_ARRAY_FOR(path, u) {
- ly_path_predicates_free(ctx, path[u].pred_type, path[u].node, path[u].predicates);
+ ly_path_predicates_free(ctx, path[u].pred_type, path[u].predicates);
}
LY_ARRAY_FREE(path);
}
diff --git a/src/path.h b/src/path.h
index 85438ed..3f8cd19 100644
--- a/src/path.h
+++ b/src/path.h
@@ -224,10 +224,9 @@
*
* @param[in] ctx libyang context.
* @param[in] pred_type Predicate type.
- * @param[in] llist Leaf-list in case of leaf-list predicate.
* @param[in] predicates Predicates ([sized array](@ref sizedarrays)) to free.
*/
-void ly_path_predicates_free(const struct ly_ctx *ctx, enum ly_path_pred_type pred_type, const struct lysc_node *llist,
+void ly_path_predicates_free(const struct ly_ctx *ctx, enum ly_path_pred_type pred_type,
struct ly_path_predicate *predicates);
/**
diff --git a/src/tree_data.c b/src/tree_data.c
index c292037..cd1f4f0 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -638,7 +638,7 @@
cleanup:
lyxp_expr_free(schema->module->ctx, expr);
- ly_path_predicates_free(schema->module->ctx, pred_type, NULL, predicates);
+ ly_path_predicates_free(schema->module->ctx, pred_type, predicates);
return ret;
}
diff --git a/src/xpath.c b/src/xpath.c
index 1e5cf39..c1dd71f 100644
--- a/src/xpath.c
+++ b/src/xpath.c
@@ -7212,7 +7212,7 @@
cleanup:
if (set) {
lydict_remove(set->ctx, ncname_dict);
- ly_path_predicates_free(set->ctx, pred_type, scnode, predicates);
+ ly_path_predicates_free(set->ctx, pred_type, predicates);
}
return rc;
}