tree data UPDATE forbid freeing keys of lists

Refs #2091
diff --git a/src/tree_data_free.c b/src/tree_data_free.c
index 806ad3c..cf6527c 100644
--- a/src/tree_data_free.c
+++ b/src/tree_data_free.c
@@ -202,6 +202,11 @@
         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 @@
     }
 
     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);
     }