tree data REFACTOR minor fixes
diff --git a/src/tree_data.c b/src/tree_data.c
index 9ccf994..f8568aa 100644
--- a/src/tree_data.c
+++ b/src/tree_data.c
@@ -3279,27 +3279,24 @@
{
struct ly_ht *ht;
uint32_t hash;
- struct lyd_leafref_links_rec rec;
+ struct lyd_leafref_links_rec rec = {0};
assert(node);
assert(record);
+ *record = NULL;
+
if (!(ly_ctx_get_options(LYD_CTX(node)) & LY_CTX_LEAFREF_LINKING)) {
- *record = NULL;
return LY_EDENIED;
}
rec.node = node;
- rec.leafref_nodes = NULL;
- rec.target_node = NULL;
-
ht = LYD_CTX(node)->leafref_links_ht;
hash = lyht_hash((const char *)&node, sizeof & node);
if (lyht_find(ht, &rec, hash, (void **)record) == LY_ENOTFOUND) {
if (create) {
LY_CHECK_RET(lyht_insert_no_check(ht, &rec, hash, (void **)record));
} else {
- *record = NULL;
return LY_ENOTFOUND;
}
}
@@ -3352,7 +3349,6 @@
struct lyd_node_term *leafref_node;
struct lysc_node_leaf *leaf_schema;
struct lysc_type_leafref *lref;
- LY_ERR ret;
LY_CHECK_ARG_RET(NULL, tree, LY_EINVAL);
@@ -3365,21 +3361,22 @@
if (elem->schema->nodetype & LYD_NODE_TERM) {
leafref_node = (struct lyd_node_term *)elem;
leaf_schema = (struct lysc_node_leaf *)elem->schema;
+
if (leaf_schema->type->basetype == LY_TYPE_LEAFREF) {
lref = (struct lysc_type_leafref *)leaf_schema->type;
if (lyplg_type_resolve_leafref(lref, elem, &leafref_node->value, tree, &target, &errmsg)) {
+ /* leafref target not found */
free(errmsg);
- } else if (target->schema->nodetype & LYD_NODE_TERM) {
- ret = lyd_link_leafref_node((struct lyd_node_term *)target, leafref_node);
- if (ret != LY_SUCCESS) {
- return ret;
- }
+ } else {
+ /* leafref target found, link it */
+ LY_CHECK_RET(lyd_link_leafref_node((struct lyd_node_term *)target, leafref_node));
}
}
}
LYD_TREE_DFS_END(sibling, elem);
}
}
+
return LY_SUCCESS;
}