From e5dc8a44ee9732dd32358b13dd52e59527e6835f Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 8 Nov 2018 02:18:38 -0200 Subject: [PATCH] lib: remove entire data tree on yang_dnode_free() For convenience, make yang_dnode_free() remove the entire data tree and not only the data node given as a parameter. Also, add a null-pointer check on nb_config_replace() before calling yang_dnode_free(). Signed-off-by: Renato Westphal --- lib/northbound.c | 3 ++- lib/yang.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/northbound.c b/lib/northbound.c index 2fabae22ba..12ca3e1006 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -236,7 +236,8 @@ void nb_config_replace(struct nb_config *config_dst, config_dst->version = config_src->version; /* Update dnode. */ - yang_dnode_free(config_dst->dnode); + if (config_dst->dnode) + yang_dnode_free(config_dst->dnode); if (preserve_source) { config_dst->dnode = yang_dnode_dup(config_src->dnode); } else { diff --git a/lib/yang.c b/lib/yang.c index 7daef79198..73f63b18e4 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -523,6 +523,8 @@ struct lyd_node *yang_dnode_dup(const struct lyd_node *dnode) void yang_dnode_free(struct lyd_node *dnode) { + while (dnode->parent) + dnode = dnode->parent; lyd_free_withsiblings(dnode); }