Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 2 | * @file tree_schema_free.c |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 4 | * @brief Freeing functions for schema tree structures. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 5 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 6 | * Copyright (c) 2019 CESNET, z.s.p.o. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 15 | #include <stdlib.h> |
| 16 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 17 | #include "common.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 18 | #include "compat.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 19 | #include "dict.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 20 | #include "log.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 21 | #include "plugins_exts.h" |
| 22 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 24 | #include "tree_data.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 25 | #include "tree_data_internal.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 26 | #include "tree_edit.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 28 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 29 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 30 | #include "xpath.h" |
| 31 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 32 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 33 | static void lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 34 | |
| 35 | static void |
| 36 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 37 | { |
| 38 | struct lysp_stmt *child, *next; |
| 39 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 40 | lydict_remove(ctx, stmt->stmt); |
| 41 | lydict_remove(ctx, stmt->arg); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 42 | ly_free_prefix_data(stmt->format, stmt->prefix_data); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 43 | |
| 44 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 45 | lysp_stmt_free(ctx, child); |
| 46 | } |
| 47 | |
| 48 | free(stmt); |
| 49 | } |
| 50 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 51 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 52 | lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext) |
| 53 | { |
| 54 | struct lysp_stmt *stmt, *next; |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 55 | struct lysp_node *node, *next_node; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 56 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 57 | lydict_remove(ctx, ext->name); |
| 58 | lydict_remove(ctx, ext->argument); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 59 | ly_free_prefix_data(ext->format, ext->prefix_data); |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 60 | LY_LIST_FOR_SAFE(ext->parsed, next_node, node) { |
| 61 | lysp_node_free(ctx, node); |
| 62 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 63 | |
| 64 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
| 65 | lysp_stmt_free(ctx, stmt); |
| 66 | } |
| 67 | } |
| 68 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 69 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 70 | lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import) |
| 71 | { |
| 72 | /* imported module is freed directly from the context's list */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 73 | lydict_remove(ctx, import->name); |
| 74 | lydict_remove(ctx, import->prefix); |
| 75 | lydict_remove(ctx, import->dsc); |
| 76 | lydict_remove(ctx, import->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 77 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 78 | } |
| 79 | |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 80 | /** |
| 81 | * @brief Common function to erase include record in main module and submodule. |
| 82 | * |
| 83 | * There is a difference since the main module is expected to have the complete list if the included submodules and |
| 84 | * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include |
| 85 | * record are freed only from main module's records. |
| 86 | * |
| 87 | * @param[in] ctx libyang context |
| 88 | * @param[in] include The include record to be erased, the record itself is not freed. |
| 89 | * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule |
| 90 | * is supposed to be freed. |
| 91 | */ |
| 92 | static void |
| 93 | lysp_include_free_(struct ly_ctx *ctx, struct lysp_include *include, ly_bool main_module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 94 | { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 95 | if (main_module && include->submodule) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 96 | lysp_module_free((struct lysp_module *)include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 97 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 98 | lydict_remove(ctx, include->name); |
| 99 | lydict_remove(ctx, include->dsc); |
| 100 | lydict_remove(ctx, include->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 101 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 102 | } |
| 103 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 104 | void |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 105 | lysp_include_free_submodule(struct ly_ctx *ctx, struct lysp_include *include) |
| 106 | { |
| 107 | return lysp_include_free_(ctx, include, 0); |
| 108 | } |
| 109 | |
| 110 | void |
| 111 | lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include) |
| 112 | { |
| 113 | return lysp_include_free_(ctx, include, 1); |
| 114 | } |
| 115 | |
| 116 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 117 | lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev) |
| 118 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 119 | lydict_remove(ctx, rev->dsc); |
| 120 | lydict_remove(ctx, rev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 121 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 122 | } |
| 123 | |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 124 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 125 | lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext) |
| 126 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 127 | lydict_remove(ctx, ext->name); |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 128 | lydict_remove(ctx, ext->argname); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 129 | lydict_remove(ctx, ext->dsc); |
| 130 | lydict_remove(ctx, ext->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 131 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 132 | if (ext->compiled) { |
| 133 | lysc_extension_free(ctx, &ext->compiled); |
| 134 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 135 | } |
| 136 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 137 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 138 | lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat) |
| 139 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 140 | lydict_remove(ctx, feat->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 141 | FREE_ARRAY(ctx, feat->iffeatures, lysp_qname_free); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 142 | FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free); |
| 143 | LY_ARRAY_FREE(feat->depfeatures); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 144 | lydict_remove(ctx, feat->dsc); |
| 145 | lydict_remove(ctx, feat->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 146 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 147 | } |
| 148 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 149 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 150 | lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident) |
| 151 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 152 | lydict_remove(ctx, ident->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 153 | FREE_ARRAY(ctx, ident->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 154 | FREE_STRINGS(ctx, ident->bases); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 155 | lydict_remove(ctx, ident->dsc); |
| 156 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 157 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 158 | } |
| 159 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 160 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 161 | lysp_restr_free(struct ly_ctx *ctx, struct lysp_restr *restr) |
| 162 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 163 | lydict_remove(ctx, restr->arg.str); |
| 164 | lydict_remove(ctx, restr->emsg); |
| 165 | lydict_remove(ctx, restr->eapptag); |
| 166 | lydict_remove(ctx, restr->dsc); |
| 167 | lydict_remove(ctx, restr->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 168 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 169 | } |
| 170 | |
| 171 | static void |
| 172 | lysp_type_enum_free(struct ly_ctx *ctx, struct lysp_type_enum *item) |
| 173 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 174 | lydict_remove(ctx, item->name); |
| 175 | lydict_remove(ctx, item->dsc); |
| 176 | lydict_remove(ctx, item->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 177 | FREE_ARRAY(ctx, item->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 178 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 179 | } |
| 180 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 181 | void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 182 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 183 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 184 | lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type) |
| 185 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 186 | lydict_remove(ctx, type->name); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 187 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 188 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 189 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 190 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 191 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 192 | lyxp_expr_free(ctx, type->path); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 193 | FREE_STRINGS(ctx, type->bases); |
| 194 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 195 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 196 | if (type->compiled) { |
| 197 | lysc_type_free(ctx, type->compiled); |
| 198 | } |
| 199 | } |
| 200 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 201 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 202 | lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf) |
| 203 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 204 | lydict_remove(ctx, tpdf->name); |
| 205 | lydict_remove(ctx, tpdf->units); |
| 206 | lydict_remove(ctx, tpdf->dflt.str); |
| 207 | lydict_remove(ctx, tpdf->dsc); |
| 208 | lydict_remove(ctx, tpdf->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 209 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 210 | |
| 211 | lysp_type_free(ctx, &tpdf->type); |
| 212 | |
| 213 | } |
| 214 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 215 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 216 | lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 217 | { |
| 218 | struct lysp_node *node, *next; |
| 219 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 220 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 221 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) { |
| 222 | lysp_node_free(ctx, node); |
| 223 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 224 | LY_LIST_FOR_SAFE(grp->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 225 | lysp_node_free(ctx, node); |
| 226 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 227 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) { |
| 228 | lysp_node_free(ctx, node); |
| 229 | } |
| 230 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) { |
| 231 | lysp_node_free(ctx, node); |
| 232 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 233 | } |
| 234 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 235 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 236 | lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when) |
| 237 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 238 | lydict_remove(ctx, when->cond); |
| 239 | lydict_remove(ctx, when->dsc); |
| 240 | lydict_remove(ctx, when->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 241 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 242 | } |
| 243 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 244 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 245 | lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 246 | { |
| 247 | struct lysp_node *node, *next; |
| 248 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 249 | LY_LIST_FOR_SAFE(augment->child, next, node) { |
| 250 | lysp_node_free(ctx, node); |
| 251 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 252 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->actions, next, node) { |
| 253 | lysp_node_free(ctx, node); |
| 254 | } |
| 255 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->notifs, next, node) { |
| 256 | lysp_node_free(ctx, node); |
| 257 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 258 | } |
| 259 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 260 | void |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 261 | lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname) |
| 262 | { |
| 263 | if (qname) { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 264 | lydict_remove(ctx, qname->str); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 265 | } |
| 266 | } |
| 267 | |
| 268 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 269 | lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d) |
| 270 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 271 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 272 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 273 | |
| 274 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 275 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 276 | case LYS_DEV_NOT_SUPPORTED: |
| 277 | /* nothing to do */ |
| 278 | break; |
| 279 | case LYS_DEV_ADD: |
| 280 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 281 | lydict_remove(ctx, add->units); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 282 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 283 | FREE_ARRAY(ctx, add->uniques, lysp_qname_free); |
| 284 | FREE_ARRAY(ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 285 | break; |
| 286 | case LYS_DEV_REPLACE: |
| 287 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 288 | lydict_remove(ctx, rpl->units); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 289 | lysp_qname_free(ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 290 | break; |
| 291 | default: |
| 292 | LOGINT(ctx); |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 297 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 298 | lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev) |
| 299 | { |
| 300 | struct lysp_deviate *next, *iter; |
| 301 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 302 | lydict_remove(ctx, dev->nodeid); |
| 303 | lydict_remove(ctx, dev->dsc); |
| 304 | lydict_remove(ctx, dev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 305 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 306 | lysp_deviate_free(ctx, iter); |
| 307 | free(iter); |
| 308 | } |
| 309 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 310 | } |
| 311 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 312 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 313 | lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref) |
| 314 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 315 | lydict_remove(ctx, ref->nodeid); |
| 316 | lydict_remove(ctx, ref->dsc); |
| 317 | lydict_remove(ctx, ref->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 318 | FREE_ARRAY(ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 319 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 320 | lydict_remove(ctx, ref->presence); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 321 | FREE_ARRAY(ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 322 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 323 | } |
| 324 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 325 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 326 | lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node) |
| 327 | { |
| 328 | struct lysp_node *child, *next; |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 329 | struct lysp_node_container *cont; |
| 330 | struct lysp_node_leaf *leaf; |
| 331 | struct lysp_node_leaflist *llist; |
| 332 | struct lysp_node_list *list; |
| 333 | struct lysp_node_choice *choice; |
| 334 | struct lysp_node_case *cas; |
| 335 | struct lysp_node_uses *uses; |
| 336 | struct lysp_node_action *act; |
| 337 | struct lysp_node_action_inout *inout; |
| 338 | struct lysp_node_notif *notif; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 339 | struct lysp_restr *musts = lysp_node_musts(node); |
| 340 | struct lysp_when *when = lysp_node_when(node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 341 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 342 | lydict_remove(ctx, node->name); |
| 343 | lydict_remove(ctx, node->dsc); |
| 344 | lydict_remove(ctx, node->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 345 | FREE_ARRAY(ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 346 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 347 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 348 | FREE_MEMBER(ctx, when, lysp_when_free); |
| 349 | FREE_ARRAY(ctx, musts, lysp_restr_free); |
| 350 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 351 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 352 | case LYS_CONTAINER: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 353 | cont = (struct lysp_node_container *)node; |
| 354 | |
| 355 | lydict_remove(ctx, cont->presence); |
| 356 | FREE_ARRAY(ctx, cont->typedefs, lysp_tpdf_free); |
| 357 | if (cont->groupings) { |
| 358 | LY_LIST_FOR_SAFE(&cont->groupings->node, next, child) { |
| 359 | lysp_node_free(ctx, child); |
| 360 | } |
| 361 | } |
| 362 | LY_LIST_FOR_SAFE(cont->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 363 | lysp_node_free(ctx, child); |
| 364 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 365 | if (cont->actions) { |
| 366 | LY_LIST_FOR_SAFE(&cont->actions->node, next, child) { |
| 367 | lysp_node_free(ctx, child); |
| 368 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 369 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 370 | if (cont->notifs) { |
| 371 | LY_LIST_FOR_SAFE(&cont->notifs->node, next, child) { |
| 372 | lysp_node_free(ctx, child); |
| 373 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 374 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 375 | break; |
| 376 | case LYS_LEAF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 377 | leaf = (struct lysp_node_leaf *)node; |
| 378 | |
| 379 | lysp_type_free(ctx, &leaf->type); |
| 380 | lydict_remove(ctx, leaf->units); |
| 381 | lydict_remove(ctx, leaf->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 382 | break; |
| 383 | case LYS_LEAFLIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 384 | llist = (struct lysp_node_leaflist *)node; |
| 385 | |
| 386 | lysp_type_free(ctx, &llist->type); |
| 387 | lydict_remove(ctx, llist->units); |
| 388 | FREE_ARRAY(ctx, llist->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 389 | break; |
| 390 | case LYS_LIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 391 | list = (struct lysp_node_list *)node; |
| 392 | |
| 393 | lydict_remove(ctx, list->key); |
| 394 | FREE_ARRAY(ctx, list->typedefs, lysp_tpdf_free); |
| 395 | if (list->groupings) { |
| 396 | LY_LIST_FOR_SAFE(&list->groupings->node, next, child) { |
| 397 | lysp_node_free(ctx, child); |
| 398 | } |
| 399 | } |
| 400 | LY_LIST_FOR_SAFE(list->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 401 | lysp_node_free(ctx, child); |
| 402 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 403 | if (list->actions) { |
| 404 | LY_LIST_FOR_SAFE(&list->actions->node, next, child) { |
| 405 | lysp_node_free(ctx, child); |
| 406 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 407 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 408 | if (list->notifs) { |
| 409 | LY_LIST_FOR_SAFE(&list->notifs->node, next, child) { |
| 410 | lysp_node_free(ctx, child); |
| 411 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 412 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 413 | FREE_ARRAY(ctx, list->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 414 | break; |
| 415 | case LYS_CHOICE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 416 | choice = (struct lysp_node_choice *)node; |
| 417 | |
| 418 | LY_LIST_FOR_SAFE(choice->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 419 | lysp_node_free(ctx, child); |
| 420 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 421 | lydict_remove(ctx, choice->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 422 | break; |
| 423 | case LYS_CASE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 424 | cas = (struct lysp_node_case *)node; |
| 425 | |
| 426 | LY_LIST_FOR_SAFE(cas->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 427 | lysp_node_free(ctx, child); |
| 428 | } |
| 429 | break; |
| 430 | case LYS_ANYDATA: |
| 431 | case LYS_ANYXML: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 432 | /* nothing special to do */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 433 | break; |
| 434 | case LYS_USES: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 435 | uses = (struct lysp_node_uses *)node; |
| 436 | |
| 437 | FREE_ARRAY(ctx, uses->refines, lysp_refine_free); |
| 438 | if (uses->augments) { |
| 439 | LY_LIST_FOR_SAFE(&uses->augments->node, next, child) { |
| 440 | lysp_node_free(ctx, child); |
| 441 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 442 | } |
| 443 | break; |
| 444 | case LYS_RPC: |
| 445 | case LYS_ACTION: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 446 | act = (struct lysp_node_action *)node; |
| 447 | |
| 448 | FREE_ARRAY(ctx, act->typedefs, lysp_tpdf_free); |
| 449 | if (act->groupings) { |
| 450 | LY_LIST_FOR_SAFE(&act->groupings->node, next, child) { |
| 451 | lysp_node_free(ctx, child); |
| 452 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 453 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 454 | if (act->input.nodetype) { |
| 455 | lysp_node_free(ctx, &act->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 456 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 457 | if (act->output.nodetype) { |
| 458 | lysp_node_free(ctx, &act->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 459 | } |
| 460 | break; |
| 461 | case LYS_INPUT: |
| 462 | case LYS_OUTPUT: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 463 | inout = (struct lysp_node_action_inout *)node; |
| 464 | |
| 465 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 466 | if (inout->groupings) { |
| 467 | LY_LIST_FOR_SAFE(&inout->groupings->node, next, child) { |
| 468 | lysp_node_free(ctx, child); |
| 469 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 470 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 471 | LY_LIST_FOR_SAFE(inout->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 472 | lysp_node_free(ctx, child); |
| 473 | } |
| 474 | /* do not free the node, it is never standalone but part of the action node */ |
| 475 | return; |
| 476 | case LYS_NOTIF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 477 | notif = (struct lysp_node_notif *)node; |
| 478 | |
| 479 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 480 | if (notif->groupings) { |
| 481 | LY_LIST_FOR_SAFE(¬if->groupings->node, next, child) { |
| 482 | lysp_node_free(ctx, child); |
| 483 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 484 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 485 | LY_LIST_FOR_SAFE(notif->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 486 | lysp_node_free(ctx, child); |
| 487 | } |
| 488 | break; |
| 489 | case LYS_GROUPING: |
| 490 | lysp_grp_free(ctx, (struct lysp_node_grp *)node); |
| 491 | break; |
| 492 | case LYS_AUGMENT: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 493 | lysp_augment_free(ctx, ((struct lysp_node_augment *)node)); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 494 | break; |
| 495 | default: |
| 496 | LOGINT(ctx); |
| 497 | } |
| 498 | |
| 499 | free(node); |
| 500 | } |
| 501 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 502 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 503 | lysp_module_free(struct lysp_module *module) |
| 504 | { |
| 505 | struct ly_ctx *ctx; |
| 506 | struct lysp_node *node, *next; |
| 507 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 508 | if (!module) { |
| 509 | return; |
| 510 | } |
| 511 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 512 | |
| 513 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 514 | FREE_ARRAY(ctx, module->includes, module->is_submod ? lysp_include_free_submodule : lysp_include_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 515 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 516 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 517 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 518 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 519 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 520 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 521 | LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) { |
| 522 | lysp_node_free(ctx, node); |
| 523 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 524 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 525 | lysp_node_free(ctx, node); |
| 526 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 527 | LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) { |
| 528 | lysp_node_free(ctx, node); |
| 529 | } |
| 530 | LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) { |
| 531 | lysp_node_free(ctx, node); |
| 532 | } |
| 533 | LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) { |
| 534 | lysp_node_free(ctx, node); |
| 535 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 536 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 537 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 538 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 539 | if (module->is_submod) { |
| 540 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 541 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 542 | lydict_remove(ctx, submod->name); |
| 543 | lydict_remove(ctx, submod->filepath); |
| 544 | lydict_remove(ctx, submod->prefix); |
| 545 | lydict_remove(ctx, submod->org); |
| 546 | lydict_remove(ctx, submod->contact); |
| 547 | lydict_remove(ctx, submod->dsc); |
| 548 | lydict_remove(ctx, submod->ref); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 549 | } |
| 550 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 551 | free(module); |
| 552 | } |
| 553 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 554 | void |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 555 | lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext) |
| 556 | { |
| 557 | if (--(*ext)->refcount) { |
| 558 | return; |
| 559 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 560 | lydict_remove(ctx, (*ext)->name); |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 561 | lydict_remove(ctx, (*ext)->argname); |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 562 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 563 | free(*ext); |
Radek Krejci | 720d261 | 2021-03-03 19:44:22 +0100 | [diff] [blame] | 564 | *ext = NULL; |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 568 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 569 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 570 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 571 | ext->def->plugin->free(ctx, ext); |
| 572 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 573 | if (ext->def) { |
| 574 | lysc_extension_free(ctx, &ext->def); |
| 575 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 576 | lydict_remove(ctx, ext->argument); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 577 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 578 | } |
| 579 | |
| 580 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 581 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 582 | { |
| 583 | LY_ARRAY_FREE(iff->features); |
| 584 | free(iff->expr); |
| 585 | } |
| 586 | |
| 587 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 588 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 589 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 590 | if (--(*w)->refcount) { |
| 591 | return; |
| 592 | } |
| 593 | lyxp_expr_free(ctx, (*w)->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 594 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, (*w)->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 595 | lydict_remove(ctx, (*w)->dsc); |
| 596 | lydict_remove(ctx, (*w)->ref); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 597 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 598 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 599 | } |
| 600 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 601 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 602 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 603 | { |
| 604 | lyxp_expr_free(ctx, must->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 605 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, must->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 606 | lydict_remove(ctx, must->emsg); |
| 607 | lydict_remove(ctx, must->eapptag); |
| 608 | lydict_remove(ctx, must->dsc); |
| 609 | lydict_remove(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 610 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 611 | } |
| 612 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 613 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 614 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 615 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 616 | lydict_remove(ctx, ident->name); |
| 617 | lydict_remove(ctx, ident->dsc); |
| 618 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 619 | LY_ARRAY_FREE(ident->derived); |
| 620 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 621 | } |
| 622 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 623 | static void |
| 624 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 625 | { |
| 626 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 627 | lydict_remove(ctx, range->eapptag); |
| 628 | lydict_remove(ctx, range->emsg); |
| 629 | lydict_remove(ctx, range->dsc); |
| 630 | lydict_remove(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 631 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 632 | } |
| 633 | |
| 634 | static void |
| 635 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 636 | { |
| 637 | if (--(*pattern)->refcount) { |
| 638 | return; |
| 639 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 640 | pcre2_code_free((*pattern)->code); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 641 | lydict_remove(ctx, (*pattern)->expr); |
| 642 | lydict_remove(ctx, (*pattern)->eapptag); |
| 643 | lydict_remove(ctx, (*pattern)->emsg); |
| 644 | lydict_remove(ctx, (*pattern)->dsc); |
| 645 | lydict_remove(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 646 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 647 | free(*pattern); |
| 648 | } |
| 649 | |
| 650 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 651 | lysc_enum_item_free(struct ly_ctx *ctx, struct lysc_type_bitenum_item *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 652 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 653 | lydict_remove(ctx, item->name); |
| 654 | lydict_remove(ctx, item->dsc); |
| 655 | lydict_remove(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 656 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 657 | } |
| 658 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 659 | static void |
| 660 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 661 | { |
| 662 | lysc_type_free(ctx, *type); |
| 663 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 664 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 665 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 666 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 667 | { |
| 668 | if (--type->refcount) { |
| 669 | return; |
| 670 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 671 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 672 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 673 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 674 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 675 | break; |
| 676 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 677 | FREE_ARRAY(ctx, (struct lysc_type_bitenum_item *)((struct lysc_type_bits *)type)->bits, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 678 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 679 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 680 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 681 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 682 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 683 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 684 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 685 | break; |
| 686 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 687 | FREE_ARRAY(ctx, ((struct lysc_type_enum *)type)->enums, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 688 | break; |
| 689 | case LY_TYPE_INT8: |
| 690 | case LY_TYPE_UINT8: |
| 691 | case LY_TYPE_INT16: |
| 692 | case LY_TYPE_UINT16: |
| 693 | case LY_TYPE_INT32: |
| 694 | case LY_TYPE_UINT32: |
| 695 | case LY_TYPE_INT64: |
| 696 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 697 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 698 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 699 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 700 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 701 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 702 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 703 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 704 | break; |
| 705 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 706 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 707 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 708 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 709 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 710 | case LY_TYPE_BOOL: |
| 711 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 712 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 713 | /* nothing to do */ |
| 714 | break; |
| 715 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 716 | |
| 717 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 718 | free(type); |
| 719 | } |
| 720 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 721 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 722 | lysc_node_action_inout_free(struct ly_ctx *ctx, struct lysc_node_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 723 | { |
| 724 | struct lysc_node *child, *child_next; |
| 725 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 726 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 727 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 728 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 729 | } |
| 730 | } |
| 731 | |
| 732 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 733 | lysc_node_action_free(struct ly_ctx *ctx, struct lysc_node_action *action) |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 734 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 735 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 736 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 737 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 738 | } |
| 739 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 740 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 741 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 742 | } |
| 743 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 744 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 745 | lysc_node_notif_free(struct ly_ctx *ctx, struct lysc_node_notif *notif) |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 746 | { |
| 747 | struct lysc_node *child, *child_next; |
| 748 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 749 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 750 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 751 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 752 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 756 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 757 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 758 | { |
| 759 | struct lysc_node *child, *child_next; |
| 760 | |
| 761 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 762 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 763 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 764 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 765 | lysc_node_free_(ctx, child); |
| 766 | } |
| 767 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 768 | lysc_node_free_(ctx, child); |
| 769 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 770 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 771 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 772 | } |
| 773 | |
| 774 | static void |
| 775 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 776 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 777 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 778 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 779 | if (node->type) { |
| 780 | lysc_type_free(ctx, node->type); |
| 781 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 782 | lydict_remove(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 783 | if (node->dflt) { |
| 784 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 785 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 786 | free(node->dflt); |
| 787 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 788 | } |
| 789 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 790 | static void |
| 791 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 792 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 793 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 794 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 795 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 796 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 797 | if (node->type) { |
| 798 | lysc_type_free(ctx, node->type); |
| 799 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 800 | lydict_remove(ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 801 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 802 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 803 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 804 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 805 | } |
| 806 | LY_ARRAY_FREE(node->dflts); |
| 807 | } |
| 808 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 809 | static void |
| 810 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 811 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 812 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 813 | struct lysc_node *child, *child_next; |
| 814 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 815 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 816 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 817 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 818 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 819 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 820 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 821 | LY_ARRAY_FOR(node->uniques, u) { |
| 822 | LY_ARRAY_FREE(node->uniques[u]); |
| 823 | } |
| 824 | LY_ARRAY_FREE(node->uniques); |
| 825 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 826 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 827 | lysc_node_free_(ctx, child); |
| 828 | } |
| 829 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 830 | lysc_node_free_(ctx, child); |
| 831 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 832 | } |
| 833 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 834 | static void |
| 835 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 836 | { |
| 837 | struct lysc_node *child, *child_next; |
| 838 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 839 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 840 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 841 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 842 | } |
| 843 | } |
| 844 | |
| 845 | static void |
| 846 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 847 | { |
| 848 | struct lysc_node *child, *child_next; |
| 849 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 850 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 851 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 852 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 853 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 854 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 855 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 856 | static void |
| 857 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 858 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 859 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 860 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 861 | } |
| 862 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 863 | static void |
| 864 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 865 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 866 | ly_bool inout = 0; |
| 867 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 868 | /* common part */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 869 | lydict_remove(ctx, node->name); |
| 870 | lydict_remove(ctx, node->dsc); |
| 871 | lydict_remove(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 872 | |
| 873 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 874 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 875 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 876 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 877 | break; |
| 878 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 879 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 880 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 881 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 882 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 883 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 884 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 885 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 886 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 887 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 888 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 889 | break; |
| 890 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 891 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 892 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 893 | case LYS_ANYDATA: |
| 894 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 895 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 896 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 897 | case LYS_RPC: |
| 898 | case LYS_ACTION: |
| 899 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 900 | break; |
| 901 | case LYS_INPUT: |
| 902 | case LYS_OUTPUT: |
| 903 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 904 | inout = 1; |
| 905 | break; |
| 906 | case LYS_NOTIF: |
| 907 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 908 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 909 | default: |
| 910 | LOGINT(ctx); |
| 911 | } |
| 912 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 913 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 914 | |
| 915 | if (!inout) { |
| 916 | free(node); |
| 917 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 918 | } |
| 919 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 920 | void |
| 921 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 922 | { |
| 923 | struct lysc_node *iter, **child_p; |
| 924 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 925 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
| 926 | /* nothing to do - inouts are part of actions and cannot be unlinked/freed separately */ |
| 927 | return; |
| 928 | } |
| 929 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 930 | if (unlink) { |
| 931 | /* unlink from siblings */ |
| 932 | if (node->prev->next) { |
| 933 | node->prev->next = node->next; |
| 934 | } |
| 935 | if (node->next) { |
| 936 | node->next->prev = node->prev; |
| 937 | } else { |
| 938 | /* unlinking the last node */ |
| 939 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 940 | if (node->nodetype == LYS_ACTION) { |
| 941 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 942 | } else if (node->nodetype == LYS_NOTIF) { |
| 943 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 944 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 945 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 946 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 947 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 948 | } else if (node->nodetype == LYS_RPC) { |
| 949 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 950 | } else if (node->nodetype == LYS_NOTIF) { |
| 951 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 952 | } else { |
| 953 | iter = node->module->compiled->data; |
| 954 | } |
| 955 | /* update the "last" pointer from the first node */ |
| 956 | iter->prev = node->prev; |
| 957 | } |
| 958 | |
| 959 | /* unlink from parent */ |
| 960 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 961 | if (node->nodetype == LYS_ACTION) { |
| 962 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 963 | } else if (node->nodetype == LYS_NOTIF) { |
| 964 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 965 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 966 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 967 | } |
| 968 | } else if (node->nodetype == LYS_RPC) { |
| 969 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 970 | } else if (node->nodetype == LYS_NOTIF) { |
| 971 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 972 | } else { |
| 973 | child_p = &node->module->compiled->data; |
| 974 | } |
| 975 | if (child_p && (*child_p == node)) { |
| 976 | /* the node is the first child */ |
| 977 | *child_p = node->next; |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | lysc_node_free_(ctx, node); |
| 982 | } |
| 983 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 984 | void |
| 985 | lysc_module_free(struct lysc_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 986 | { |
| 987 | struct ly_ctx *ctx; |
| 988 | struct lysc_node *node, *node_next; |
| 989 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 990 | if (!module) { |
| 991 | return; |
| 992 | } |
| 993 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 994 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 995 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 996 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 997 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 998 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 999 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 1000 | lysc_node_free_(ctx, node); |
| 1001 | } |
| 1002 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 1003 | lysc_node_free_(ctx, node); |
| 1004 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1005 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 1006 | |
| 1007 | free(module); |
| 1008 | } |
| 1009 | |
| 1010 | void |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1011 | lys_module_free(struct lys_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1012 | { |
| 1013 | if (!module) { |
| 1014 | return; |
| 1015 | } |
| 1016 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1017 | lysc_module_free(module->compiled); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 1018 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1019 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1020 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1021 | LY_ARRAY_FREE(module->augmented_by); |
| 1022 | LY_ARRAY_FREE(module->deviated_by); |
| 1023 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1024 | lydict_remove(module->ctx, module->name); |
| 1025 | lydict_remove(module->ctx, module->revision); |
| 1026 | lydict_remove(module->ctx, module->ns); |
| 1027 | lydict_remove(module->ctx, module->prefix); |
| 1028 | lydict_remove(module->ctx, module->filepath); |
| 1029 | lydict_remove(module->ctx, module->org); |
| 1030 | lydict_remove(module->ctx, module->contact); |
| 1031 | lydict_remove(module->ctx, module->dsc); |
| 1032 | lydict_remove(module->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1033 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1034 | free(module); |
| 1035 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 1036 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1037 | API void |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 1038 | lyplg_ext_instance_substatements_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1039 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1040 | LY_ARRAY_COUNT_TYPE u; |
| 1041 | |
| 1042 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1043 | if (!substmts[u].storage) { |
| 1044 | continue; |
| 1045 | } |
| 1046 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1047 | switch (substmts[u].stmt) { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1048 | case LY_STMT_ACTION: |
| 1049 | case LY_STMT_ANYDATA: |
| 1050 | case LY_STMT_ANYXML: |
| 1051 | case LY_STMT_CONTAINER: |
| 1052 | case LY_STMT_CHOICE: |
| 1053 | case LY_STMT_LEAF: |
| 1054 | case LY_STMT_LEAF_LIST: |
| 1055 | case LY_STMT_LIST: |
| 1056 | case LY_STMT_NOTIFICATION: |
| 1057 | case LY_STMT_RPC: |
| 1058 | case LY_STMT_USES: { |
| 1059 | struct lysc_node *child, *child_next; |
| 1060 | |
| 1061 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
| 1062 | lysc_node_free_(ctx, child); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1063 | } |
| 1064 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1065 | } |
| 1066 | case LY_STMT_CONFIG: |
| 1067 | case LY_STMT_STATUS: |
| 1068 | /* nothing to do */ |
| 1069 | break; |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1070 | case LY_STMT_DESCRIPTION: |
| 1071 | case LY_STMT_REFERENCE: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1072 | case LY_STMT_UNITS: |
| 1073 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1074 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1075 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1076 | if (!str) { |
| 1077 | break; |
| 1078 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1079 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1080 | } else { |
| 1081 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1082 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1083 | if (!strs) { |
| 1084 | break; |
| 1085 | } |
| 1086 | FREE_STRINGS(ctx, strs); |
| 1087 | } |
| 1088 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1089 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1090 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1091 | if (!iff) { |
| 1092 | break; |
| 1093 | } |
| 1094 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1095 | /* single item */ |
| 1096 | lysc_iffeature_free(ctx, iff); |
| 1097 | free(iff); |
| 1098 | } else { |
| 1099 | /* multiple items */ |
| 1100 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1101 | } |
| 1102 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1103 | case LY_STMT_TYPE: |
| 1104 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1105 | /* single item */ |
| 1106 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
| 1107 | if (!type) { |
| 1108 | break; |
| 1109 | } |
| 1110 | lysc_type_free(ctx, type); |
| 1111 | } else { |
| 1112 | /* multiple items */ |
| 1113 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
| 1114 | if (!types) { |
| 1115 | break; |
| 1116 | } |
| 1117 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1118 | } |
| 1119 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1122 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1123 | default: |
| 1124 | LOGINT(ctx); |
| 1125 | } |
| 1126 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1127 | |
| 1128 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1129 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1130 | |
| 1131 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1132 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1133 | { |
| 1134 | if (ctx) { |
| 1135 | free(ctx); |
| 1136 | } |
| 1137 | } |
| 1138 | |
| 1139 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1140 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1141 | { |
| 1142 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1143 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1144 | free(ctx); |
| 1145 | } |
| 1146 | } |