Skip to content

Commit

Permalink
mgmtd: fix printing an empty data tree
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
idryzhov committed Jan 28, 2024
1 parent 7bce263 commit f576e2d
Showing 1 changed file with 0 additions and 8 deletions.
8 changes: 0 additions & 8 deletions mgmtd/mgmt_fe_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 */
Expand All @@ -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;
Expand Down

0 comments on commit f576e2d

Please sign in to comment.