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