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