-
Notifications
You must be signed in to change notification settings - Fork 314
Closed
Description
I would like to suggest including a function that frees whole data tree including siblings. It doesn't make difference if there is only one node at root level, however if there are multiple nodes it would be handy. Currently, you can read data tree by one function call but you have to use loop to free it.
Example:
module example-module {
namespace "urn:ietf:params:xml:ns:yang:example";
prefix ie;
organization "organization";
description "example yang module";
contact "contact@example.com";
container container {
config true;
list list {
leaf leaf {
type string;
}
leaf key1 {
type string;
}
key "key1";
}
}
leaf-list number{
type uint16;
}
}
FILE *data = fopen("example-module.data","r");
struct lyd_node *data_tree = lyd_parse_fd(ctx, fileno(data), LYD_XML, 0);
fclose(data);
lyd_free(data_tree); /*This causes MEMLEAK if data contains container and leaflist*/
My suggestion:
/**
* Free the subtree and its siblings.
* @param [in] root
*/
void lyd_free_datatree(struct lyd_node *root){
struct lyd_node *next = NULL;
while(NULL != root){
next = root->next;
lyd_free(root);
root = next;
}
}
(The function name could be also lyd_free_with_siblings
.)
What do you think? Or is there something I've overlooked?
Metadata
Metadata
Assignees
Labels
No labels