Skip to content

Commit

Permalink
tree data UPDATE forbid freeing keys of lists
Browse files Browse the repository at this point in the history
Refs #2091
  • Loading branch information
michalvasko committed Sep 4, 2023
1 parent b5992f5 commit 0dc4a26
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/tree_data_free.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}
Expand Down

0 comments on commit 0dc4a26

Please sign in to comment.