From 0dc4a26ca6e685356e6092bb39aed1baeb024ac2 Mon Sep 17 00:00:00 2001 From: Michal Vasko Date: Mon, 4 Sep 2023 09:27:24 +0200 Subject: [PATCH] tree data UPDATE forbid freeing keys of lists Refs #2091 --- src/tree_data_free.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/tree_data_free.c b/src/tree_data_free.c index 806ad3cf9..cf6527c6a 100644 --- a/src/tree_data_free.c +++ b/src/tree_data_free.c @@ -202,6 +202,11 @@ lyd_free_tree(struct lyd_node *node) return; } + if (lysc_is_key(node->schema) && node->parent) { + LOGERR(LYD_CTX(node), LY_EINVAL, "Cannot free a list key \"%s\", free the list instance instead.", LYD_NAME(node)); + return; + } + lyd_free_subtree(node, 1); } @@ -223,6 +228,11 @@ lyd_free_(struct lyd_node *node, ly_bool top) } LY_LIST_FOR_SAFE(node, next, iter) { + if (lysc_is_key(iter->schema) && iter->parent) { + LOGERR(LYD_CTX(node), LY_EINVAL, "Cannot free a list key \"%s\", free the list instance instead.", LYD_NAME(iter)); + return; + } + /* in case of the top-level nodes (node->parent is NULL), no unlinking needed */ lyd_free_subtree(iter, iter->parent ? 1 : 0); }