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 | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 25 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 26 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 27 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 28 | #include "xpath.h" |
| 29 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 30 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 31 | void lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext); |
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); |
| 123 | lydict_remove(ctx, ext->argument); |
| 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); |
| 506 | lydict_remove(ctx, (*ext)->argument); |
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); |
| 509 | } |
| 510 | |
| 511 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 512 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 513 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 514 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 515 | ext->def->plugin->free(ctx, ext); |
| 516 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 517 | if (ext->def) { |
| 518 | lysc_extension_free(ctx, &ext->def); |
| 519 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 520 | lydict_remove(ctx, ext->argument); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 521 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 522 | } |
| 523 | |
| 524 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 525 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 526 | { |
| 527 | LY_ARRAY_FREE(iff->features); |
| 528 | free(iff->expr); |
| 529 | } |
| 530 | |
| 531 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 532 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 533 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 534 | if (--(*w)->refcount) { |
| 535 | return; |
| 536 | } |
| 537 | lyxp_expr_free(ctx, (*w)->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 538 | lysc_prefixes_free((*w)->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 539 | lydict_remove(ctx, (*w)->dsc); |
| 540 | lydict_remove(ctx, (*w)->ref); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 541 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 542 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 545 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 546 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 547 | { |
| 548 | lyxp_expr_free(ctx, must->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 549 | lysc_prefixes_free(must->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 550 | lydict_remove(ctx, must->emsg); |
| 551 | lydict_remove(ctx, must->eapptag); |
| 552 | lydict_remove(ctx, must->dsc); |
| 553 | lydict_remove(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 554 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 555 | } |
| 556 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 557 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 558 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 559 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 560 | lydict_remove(ctx, ident->name); |
| 561 | lydict_remove(ctx, ident->dsc); |
| 562 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 563 | LY_ARRAY_FREE(ident->derived); |
| 564 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 565 | } |
| 566 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 567 | static void |
| 568 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 569 | { |
| 570 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 571 | lydict_remove(ctx, range->eapptag); |
| 572 | lydict_remove(ctx, range->emsg); |
| 573 | lydict_remove(ctx, range->dsc); |
| 574 | lydict_remove(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 575 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 576 | } |
| 577 | |
| 578 | static void |
| 579 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 580 | { |
| 581 | if (--(*pattern)->refcount) { |
| 582 | return; |
| 583 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 584 | pcre2_code_free((*pattern)->code); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 585 | lydict_remove(ctx, (*pattern)->expr); |
| 586 | lydict_remove(ctx, (*pattern)->eapptag); |
| 587 | lydict_remove(ctx, (*pattern)->emsg); |
| 588 | lydict_remove(ctx, (*pattern)->dsc); |
| 589 | lydict_remove(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 590 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 591 | free(*pattern); |
| 592 | } |
| 593 | |
| 594 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 595 | 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] | 596 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 597 | lydict_remove(ctx, item->name); |
| 598 | lydict_remove(ctx, item->dsc); |
| 599 | lydict_remove(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 600 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 601 | } |
| 602 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 603 | static void |
| 604 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 605 | { |
| 606 | lysc_type_free(ctx, *type); |
| 607 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 608 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 609 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 610 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 611 | { |
| 612 | if (--type->refcount) { |
| 613 | return; |
| 614 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 615 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 616 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 617 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 618 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 619 | break; |
| 620 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 621 | 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] | 622 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 623 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 624 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 625 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 626 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 627 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 628 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 629 | break; |
| 630 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 631 | 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] | 632 | break; |
| 633 | case LY_TYPE_INT8: |
| 634 | case LY_TYPE_UINT8: |
| 635 | case LY_TYPE_INT16: |
| 636 | case LY_TYPE_UINT16: |
| 637 | case LY_TYPE_INT32: |
| 638 | case LY_TYPE_UINT32: |
| 639 | case LY_TYPE_INT64: |
| 640 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 641 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 642 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 643 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 644 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 645 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 646 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 647 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 648 | break; |
| 649 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 650 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 651 | lysc_prefixes_free(((struct lysc_type_leafref *)type)->prefixes); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 652 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 653 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 654 | case LY_TYPE_BOOL: |
| 655 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 656 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 657 | /* nothing to do */ |
| 658 | break; |
| 659 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 660 | |
| 661 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 662 | free(type); |
| 663 | } |
| 664 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 665 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 666 | 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] | 667 | { |
| 668 | struct lysc_node *child, *child_next; |
| 669 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 670 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 671 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 672 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 673 | } |
| 674 | } |
| 675 | |
| 676 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 677 | 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] | 678 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 679 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 680 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 681 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 682 | } |
| 683 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 684 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 685 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 686 | } |
| 687 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 688 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 689 | 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] | 690 | { |
| 691 | struct lysc_node *child, *child_next; |
| 692 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 693 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 694 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 695 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 696 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 697 | } |
| 698 | } |
| 699 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 700 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 701 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 702 | { |
| 703 | struct lysc_node *child, *child_next; |
| 704 | |
| 705 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 706 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 707 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 708 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 709 | lysc_node_free_(ctx, child); |
| 710 | } |
| 711 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 712 | lysc_node_free_(ctx, child); |
| 713 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 714 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 715 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 716 | } |
| 717 | |
| 718 | static void |
| 719 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 720 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 721 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 722 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 723 | if (node->type) { |
| 724 | lysc_type_free(ctx, node->type); |
| 725 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 726 | lydict_remove(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 727 | if (node->dflt) { |
| 728 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 729 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 730 | free(node->dflt); |
| 731 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 732 | } |
| 733 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 734 | static void |
| 735 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 736 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 737 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 738 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 739 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 740 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 741 | if (node->type) { |
| 742 | lysc_type_free(ctx, node->type); |
| 743 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 744 | lydict_remove(ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 745 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 746 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 747 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 748 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 749 | } |
| 750 | LY_ARRAY_FREE(node->dflts); |
| 751 | } |
| 752 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 753 | static void |
| 754 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 755 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 756 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 757 | struct lysc_node *child, *child_next; |
| 758 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 759 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 760 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 761 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 762 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 763 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 764 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 765 | LY_ARRAY_FOR(node->uniques, u) { |
| 766 | LY_ARRAY_FREE(node->uniques[u]); |
| 767 | } |
| 768 | LY_ARRAY_FREE(node->uniques); |
| 769 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 770 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 771 | lysc_node_free_(ctx, child); |
| 772 | } |
| 773 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 774 | lysc_node_free_(ctx, child); |
| 775 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 778 | static void |
| 779 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 780 | { |
| 781 | struct lysc_node *child, *child_next; |
| 782 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 783 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 784 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 785 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 786 | } |
| 787 | } |
| 788 | |
| 789 | static void |
| 790 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 791 | { |
| 792 | struct lysc_node *child, *child_next; |
| 793 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 794 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 795 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 796 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 797 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 798 | } |
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 | static void |
| 801 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 802 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 803 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 804 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 805 | } |
| 806 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 807 | static void |
| 808 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 809 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 810 | ly_bool inout = 0; |
| 811 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 812 | /* common part */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 813 | lydict_remove(ctx, node->name); |
| 814 | lydict_remove(ctx, node->dsc); |
| 815 | lydict_remove(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 816 | |
| 817 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 818 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 819 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 820 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 821 | break; |
| 822 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 823 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 824 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 825 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 826 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 827 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 828 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 829 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 830 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 831 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 832 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 833 | break; |
| 834 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 835 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 836 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 837 | case LYS_ANYDATA: |
| 838 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 839 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 840 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 841 | case LYS_RPC: |
| 842 | case LYS_ACTION: |
| 843 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 844 | break; |
| 845 | case LYS_INPUT: |
| 846 | case LYS_OUTPUT: |
| 847 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 848 | inout = 1; |
| 849 | break; |
| 850 | case LYS_NOTIF: |
| 851 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 852 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 853 | default: |
| 854 | LOGINT(ctx); |
| 855 | } |
| 856 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 857 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 858 | |
| 859 | if (!inout) { |
| 860 | free(node); |
| 861 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 862 | } |
| 863 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 864 | void |
| 865 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 866 | { |
| 867 | struct lysc_node *iter, **child_p; |
| 868 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 869 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
| 870 | /* nothing to do - inouts are part of actions and cannot be unlinked/freed separately */ |
| 871 | return; |
| 872 | } |
| 873 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 874 | if (unlink) { |
| 875 | /* unlink from siblings */ |
| 876 | if (node->prev->next) { |
| 877 | node->prev->next = node->next; |
| 878 | } |
| 879 | if (node->next) { |
| 880 | node->next->prev = node->prev; |
| 881 | } else { |
| 882 | /* unlinking the last node */ |
| 883 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 884 | if (node->nodetype == LYS_ACTION) { |
| 885 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 886 | } else if (node->nodetype == LYS_NOTIF) { |
| 887 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 888 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 889 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 890 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 891 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 892 | } else if (node->nodetype == LYS_RPC) { |
| 893 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 894 | } else if (node->nodetype == LYS_NOTIF) { |
| 895 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 896 | } else { |
| 897 | iter = node->module->compiled->data; |
| 898 | } |
| 899 | /* update the "last" pointer from the first node */ |
| 900 | iter->prev = node->prev; |
| 901 | } |
| 902 | |
| 903 | /* unlink from parent */ |
| 904 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 905 | if (node->nodetype == LYS_ACTION) { |
| 906 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 907 | } else if (node->nodetype == LYS_NOTIF) { |
| 908 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 909 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 910 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 911 | } |
| 912 | } else if (node->nodetype == LYS_RPC) { |
| 913 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 914 | } else if (node->nodetype == LYS_NOTIF) { |
| 915 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 916 | } else { |
| 917 | child_p = &node->module->compiled->data; |
| 918 | } |
| 919 | if (child_p && (*child_p == node)) { |
| 920 | /* the node is the first child */ |
| 921 | *child_p = node->next; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | lysc_node_free_(ctx, node); |
| 926 | } |
| 927 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 928 | static void |
| 929 | lysc_module_free_(struct lysc_module *module) |
| 930 | { |
| 931 | struct ly_ctx *ctx; |
| 932 | struct lysc_node *node, *node_next; |
| 933 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 934 | LY_CHECK_ARG_RET(NULL, module, ); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 935 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 936 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 937 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 938 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 939 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 940 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 941 | lysc_node_free_(ctx, node); |
| 942 | } |
| 943 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 944 | lysc_node_free_(ctx, node); |
| 945 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 946 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 947 | |
| 948 | free(module); |
| 949 | } |
| 950 | |
| 951 | void |
| 952 | lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 953 | { |
Radek Krejci | 9b04289 | 2019-02-13 14:28:44 +0100 | [diff] [blame] | 954 | /* TODO use the destructor, this just suppress warning about unused parameter */ |
| 955 | (void) private_destructor; |
| 956 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 957 | if (module) { |
| 958 | lysc_module_free_(module); |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | void |
| 963 | lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 964 | { |
| 965 | if (!module) { |
| 966 | return; |
| 967 | } |
| 968 | |
| 969 | lysc_module_free(module->compiled, private_destructor); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 970 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 971 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 972 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 973 | LY_ARRAY_FREE(module->augmented_by); |
| 974 | LY_ARRAY_FREE(module->deviated_by); |
| 975 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 976 | lydict_remove(module->ctx, module->name); |
| 977 | lydict_remove(module->ctx, module->revision); |
| 978 | lydict_remove(module->ctx, module->ns); |
| 979 | lydict_remove(module->ctx, module->prefix); |
| 980 | lydict_remove(module->ctx, module->filepath); |
| 981 | lydict_remove(module->ctx, module->org); |
| 982 | lydict_remove(module->ctx, module->contact); |
| 983 | lydict_remove(module->ctx, module->dsc); |
| 984 | lydict_remove(module->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 985 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 986 | free(module); |
| 987 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 988 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 989 | API void |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 990 | 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] | 991 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 992 | LY_ARRAY_COUNT_TYPE u; |
| 993 | |
| 994 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 995 | if (!substmts[u].storage) { |
| 996 | continue; |
| 997 | } |
| 998 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 999 | switch (substmts[u].stmt) { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1000 | case LY_STMT_ACTION: |
| 1001 | case LY_STMT_ANYDATA: |
| 1002 | case LY_STMT_ANYXML: |
| 1003 | case LY_STMT_CONTAINER: |
| 1004 | case LY_STMT_CHOICE: |
| 1005 | case LY_STMT_LEAF: |
| 1006 | case LY_STMT_LEAF_LIST: |
| 1007 | case LY_STMT_LIST: |
| 1008 | case LY_STMT_NOTIFICATION: |
| 1009 | case LY_STMT_RPC: |
| 1010 | case LY_STMT_USES: { |
| 1011 | struct lysc_node *child, *child_next; |
| 1012 | |
| 1013 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
| 1014 | lysc_node_free_(ctx, child); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1015 | } |
| 1016 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1017 | } |
| 1018 | case LY_STMT_CONFIG: |
| 1019 | case LY_STMT_STATUS: |
| 1020 | /* nothing to do */ |
| 1021 | break; |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1022 | case LY_STMT_DESCRIPTION: |
| 1023 | case LY_STMT_REFERENCE: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1024 | case LY_STMT_UNITS: |
| 1025 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1026 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1027 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1028 | if (!str) { |
| 1029 | break; |
| 1030 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1031 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1032 | } else { |
| 1033 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1034 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1035 | if (!strs) { |
| 1036 | break; |
| 1037 | } |
| 1038 | FREE_STRINGS(ctx, strs); |
| 1039 | } |
| 1040 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1041 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1042 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1043 | if (!iff) { |
| 1044 | break; |
| 1045 | } |
| 1046 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1047 | /* single item */ |
| 1048 | lysc_iffeature_free(ctx, iff); |
| 1049 | free(iff); |
| 1050 | } else { |
| 1051 | /* multiple items */ |
| 1052 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1053 | } |
| 1054 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1055 | case LY_STMT_TYPE: |
| 1056 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1057 | /* single item */ |
| 1058 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
| 1059 | if (!type) { |
| 1060 | break; |
| 1061 | } |
| 1062 | lysc_type_free(ctx, type); |
| 1063 | } else { |
| 1064 | /* multiple items */ |
| 1065 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
| 1066 | if (!types) { |
| 1067 | break; |
| 1068 | } |
| 1069 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1070 | } |
| 1071 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1072 | } |
| 1073 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1074 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1075 | default: |
| 1076 | LOGINT(ctx); |
| 1077 | } |
| 1078 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1079 | |
| 1080 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1081 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1082 | |
| 1083 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1084 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1085 | { |
| 1086 | if (ctx) { |
| 1087 | free(ctx); |
| 1088 | } |
| 1089 | } |
| 1090 | |
| 1091 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1092 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1093 | { |
| 1094 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1095 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1096 | free(ctx); |
| 1097 | } |
| 1098 | } |