context UPDATE support for storing leafref references (#2155)

* Adding leafref references and API to lyd_node_term

* Adjusted to require context flag

* Extended the utest for tree_data

* Fixed typo in docs

* Refactored based on PR discussion

* Refactored to use hash table for leafref nodes
diff --git a/src/tree_data_new.c b/src/tree_data_new.c
index 5d9f429..e56e61e 100644
--- a/src/tree_data_new.c
+++ b/src/tree_data_new.c
@@ -1315,6 +1315,11 @@
         val_change = 0;
     }
 
+    /* clear links to leafref nodes */
+    if (ly_ctx_get_options(LYD_CTX(term)) & LY_CTX_LEAFREF_LINKING) {
+        lyd_free_leafref_nodes(t);
+    }
+
     /* always clear the default flag */
     if (term->flags & LYD_DEFAULT) {
         for (parent = term; parent; parent = lyd_parent(parent)) {