lyd_free_internal_r(struct lyd_node *node, int top)
{
    struct lyd_node *next, *iter;

    if (!node) {
        return;
    }

    /* if freeing top-level, always remove it from the parent hash table */
    lyd_unlink_internal(node, (top ? 1 : 2));

    if (!(node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) {
        /* free children */
        LY_TREE_FOR_SAFE(node->child, next, iter) {
            lyd_free_internal_r(iter, 0);
        }
    }

    _lyd_free_node(node);
}
lyd_free_internal_r(struct lyd_node *node, int top)
{
    struct lyd_node *next, *iter;

    if (!node) {
        return;
    }

     
    lyd_unlink_internal(node, (top ? 1 : 2));

    if (!(node->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA))) {
         
        LY_TREE_FOR_SAFE(node->child, next, iter) {
            lyd_free_internal_r(iter, 0);
        }
    }

    _lyd_free_node(node);
}