summaryrefslogtreecommitdiff
path: root/lib/northbound.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2023-11-11 02:06:11 +0200
committerIgor Ryzhov <iryzhov@nfware.com>2023-11-11 02:18:24 +0200
commit814b9fb7722ffcc5ce8232137400fc717b2d9066 (patch)
tree6f804e5bc8fbaec05d2d937c71c2eca29f36e779 /lib/northbound.c
parent19bcca4f2e9a3ee3c8cc16608dcf303241bbf014 (diff)
lib: fix possible freeing of libyang data
mgmtd frees all non-NULL change->value variables at the end of every commit. We shouldn't assign change->value with data returned by libyang to prevent freeing of library-allocated memory. Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
Diffstat (limited to 'lib/northbound.c')
-rw-r--r--lib/northbound.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index 080f3d002e..249c3f2f6e 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -777,6 +777,7 @@ void nb_candidate_edit_config_changes(
struct nb_cfg_change *change = &cfg_changes[i];
struct nb_node *nb_node;
char xpath[XPATH_MAXLEN];
+ const char *value;
struct yang_data *data;
int ret;
@@ -814,9 +815,10 @@ void nb_candidate_edit_config_changes(
}
/* If the value is not set, get the default if it exists. */
- if (change->value == NULL)
- change->value = yang_snode_get_default(nb_node->snode);
- data = yang_data_new(xpath, change->value);
+ value = change->value;
+ if (value == NULL)
+ value = yang_snode_get_default(nb_node->snode);
+ data = yang_data_new(xpath, value);
/*
* Ignore "not found" errors when editing the candidate