From 2e4ec826fcade346b8931ed8a5c643dedbc608f3 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Sun, 28 Jan 2024 02:35:14 +0200 Subject: [PATCH] mgmtd: fix printing an empty data tree We don't need to create an actual tree to print an empty tree, libyang handles NULL just fine. The actual problem is that `yang_dnode_new` creates a tree by validating it, and the validation creates all implicit default nodes. Therefore, when called with "with-default" flags, instead of getting an empty tree, we get a tree with all top-level default set. Signed-off-by: Igor Ryzhov --- mgmtd/mgmt_fe_adapter.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mgmtd/mgmt_fe_adapter.c b/mgmtd/mgmt_fe_adapter.c index 9e0a5ef0607a..5f552708266a 100644 --- a/mgmtd/mgmt_fe_adapter.c +++ b/mgmtd/mgmt_fe_adapter.c @@ -1086,7 +1086,6 @@ static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session, { struct mgmt_msg_tree_data *msg; - struct lyd_node *empty = NULL; uint8_t *buf = NULL; int ret = 0; @@ -1098,11 +1097,6 @@ static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session, msg->partial_error = partial_error; msg->result_type = result_type; - if (!tree) { - empty = yang_dnode_new(ly_native_ctx, false); - tree = empty; - } - ret = yang_print_tree_append(&buf, tree, result_type, (wd_options | LYD_PRINT_WITHSIBLINGS)); /* buf may have been reallocated and moved */ @@ -1126,8 +1120,6 @@ static int fe_adapter_send_tree_data(struct mgmt_fe_session_ctx *session, ret = fe_adapter_send_native_msg(session->adapter, buf, darr_len(buf), short_circuit_ok); done: - if (empty) - yang_dnode_free(empty); darr_free(buf); return ret;