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> |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 5 | * @brief Freeing functions for schema tree structures. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 6 | * |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 16 | #include "tree_schema_free.h" |
| 17 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 18 | #include <assert.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 21 | #include "common.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 22 | #include "compat.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 23 | #include "dict.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 24 | #include "log.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 25 | #include "plugins_exts.h" |
| 26 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 28 | #include "tree_data.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 29 | #include "tree_data_internal.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 30 | #include "tree_edit.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 31 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 32 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 33 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 34 | #include "xpath.h" |
| 35 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 36 | static void lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 37 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 38 | void |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 39 | lysp_qname_free(const struct ly_ctx *ctx, struct lysp_qname *qname) |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 40 | { |
| 41 | if (qname) { |
| 42 | lydict_remove(ctx, qname->str); |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @brief Free the parsed generic statement structure. |
| 48 | * |
| 49 | * @param[in] ctx libyang context. |
| 50 | * @param[in] grp Parsed schema statement structure to free. Note that the structure itself is not freed. |
| 51 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 52 | static void |
| 53 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 54 | { |
| 55 | struct lysp_stmt *child, *next; |
| 56 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 57 | lydict_remove(ctx, stmt->stmt); |
| 58 | lydict_remove(ctx, stmt->arg); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 59 | ly_free_prefix_data(stmt->format, stmt->prefix_data); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 60 | |
| 61 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 62 | lysp_stmt_free(ctx, child); |
| 63 | } |
| 64 | |
| 65 | free(stmt); |
| 66 | } |
| 67 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 68 | void |
| 69 | lysp_ext_instance_free(struct lysf_ctx *ctx, struct lysp_ext_instance *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 70 | { |
| 71 | struct lysp_stmt *stmt, *next; |
| 72 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 73 | lydict_remove(ctx->ctx, ext->name); |
| 74 | lydict_remove(ctx->ctx, ext->argument); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 75 | ly_free_prefix_data(ext->format, ext->prefix_data); |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 76 | if (ext->record && ext->record->plugin.pfree) { |
| 77 | ext->record->plugin.pfree(ctx->ctx, ext); |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 78 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 79 | |
| 80 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 81 | lysp_stmt_free(ctx->ctx, stmt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 85 | /** |
| 86 | * @brief Free the parsed import structure. |
| 87 | * |
| 88 | * @param[in] ctx Free context. |
| 89 | * @param[in] import Parsed schema import structure to free. Note that the structure itself is not freed. |
| 90 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 91 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 92 | lysp_import_free(struct lysf_ctx *ctx, struct lysp_import *import) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 93 | { |
| 94 | /* imported module is freed directly from the context's list */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 95 | lydict_remove(ctx->ctx, import->name); |
| 96 | lydict_remove(ctx->ctx, import->prefix); |
| 97 | lydict_remove(ctx->ctx, import->dsc); |
| 98 | lydict_remove(ctx->ctx, import->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 99 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 100 | } |
| 101 | |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 102 | /** |
| 103 | * @brief Common function to erase include record in main module and submodule. |
| 104 | * |
| 105 | * There is a difference since the main module is expected to have the complete list if the included submodules and |
| 106 | * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include |
| 107 | * record are freed only from main module's records. |
| 108 | * |
| 109 | * @param[in] ctx libyang context |
| 110 | * @param[in] include The include record to be erased, the record itself is not freed. |
| 111 | * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule |
| 112 | * is supposed to be freed. |
| 113 | */ |
| 114 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 115 | lysp_include_free_(struct lysf_ctx *ctx, struct lysp_include *include, ly_bool main_module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 116 | { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 117 | if (main_module && include->submodule) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 118 | lysp_module_free(ctx, (struct lysp_module *)include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 119 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 120 | lydict_remove(ctx->ctx, include->name); |
| 121 | lydict_remove(ctx->ctx, include->dsc); |
| 122 | lydict_remove(ctx->ctx, include->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 123 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 124 | } |
| 125 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 126 | /** |
| 127 | * @brief Free the parsed include structure of a submodule. |
| 128 | * |
| 129 | * @param[in] ctx Free context. |
| 130 | * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed. |
| 131 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 132 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 133 | lysp_include_free_submodule(struct lysf_ctx *ctx, struct lysp_include *include) |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 134 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 135 | lysp_include_free_(ctx, include, 0); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 138 | /** |
| 139 | * @brief Free the parsed include structure of a module. |
| 140 | * |
| 141 | * @param[in] ctx Free context. |
| 142 | * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed. |
| 143 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 144 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 145 | lysp_include_free(struct lysf_ctx *ctx, struct lysp_include *include) |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 146 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 147 | lysp_include_free_(ctx, include, 1); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 150 | /** |
| 151 | * @brief Free the parsed revision structure. |
| 152 | * |
| 153 | * @param[in] ctx Free context. |
| 154 | * @param[in] rev Parsed schema revision structure to free. Note that the structure itself is not freed. |
| 155 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 156 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 157 | lysp_revision_free(struct lysf_ctx *ctx, struct lysp_revision *rev) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 158 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 159 | lydict_remove(ctx->ctx, rev->dsc); |
| 160 | lydict_remove(ctx->ctx, rev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 161 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 162 | } |
| 163 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 164 | /** |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 165 | * @brief Free the compiled extension definition and NULL the provided pointer. |
| 166 | * |
| 167 | * @param[in] ctx Free context. |
| 168 | * @param[in,out] ext Compiled extension definition to be freed. |
| 169 | */ |
| 170 | static void |
| 171 | lysc_extension_free(struct lysf_ctx *ctx, struct lysc_ext **ext) |
| 172 | { |
| 173 | if (ly_set_contains(&ctx->ext_set, *ext, NULL)) { |
| 174 | /* already freed and only referenced again in this module */ |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | /* remember this extension to be freed, nothing to do on error */ |
| 179 | (void)ly_set_add(&ctx->ext_set, *ext, 0, NULL); |
| 180 | |
| 181 | /* recursive exts free */ |
| 182 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 183 | |
| 184 | *ext = NULL; |
| 185 | } |
| 186 | |
| 187 | /** |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 188 | * @brief Free the parsed ext structure. |
| 189 | * |
| 190 | * @param[in] ctx Free context. |
| 191 | * @param[in] ext Parsed schema ext structure to free. Note that the structure itself is not freed. |
| 192 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 193 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 194 | lysp_ext_free(struct lysf_ctx *ctx, struct lysp_ext *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 195 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 196 | lydict_remove(ctx->ctx, ext->name); |
| 197 | lydict_remove(ctx->ctx, ext->argname); |
| 198 | lydict_remove(ctx->ctx, ext->dsc); |
| 199 | lydict_remove(ctx->ctx, ext->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 200 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 201 | if (ext->compiled) { |
| 202 | lysc_extension_free(ctx, &ext->compiled); |
| 203 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 204 | } |
| 205 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 206 | /** |
| 207 | * @brief Free the parsed feature structure. |
| 208 | * |
| 209 | * @param[in] ctx Free context. |
| 210 | * @param[in] feat Parsed schema feature structure to free. Note that the structure itself is not freed. |
| 211 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 212 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 213 | lysp_feature_free(struct lysf_ctx *ctx, struct lysp_feature *feat) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 214 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 215 | lydict_remove(ctx->ctx, feat->name); |
| 216 | FREE_ARRAY(ctx->ctx, feat->iffeatures, lysp_qname_free); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 217 | FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free); |
| 218 | LY_ARRAY_FREE(feat->depfeatures); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 219 | lydict_remove(ctx->ctx, feat->dsc); |
| 220 | lydict_remove(ctx->ctx, feat->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 221 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 222 | } |
| 223 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 224 | /** |
| 225 | * @brief Free the parsed identity structure. |
| 226 | * |
| 227 | * @param[in] ctx Free context. |
| 228 | * @param[in] ident Parsed schema identity structure to free. Note that the structure itself is not freed. |
| 229 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 230 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 231 | lysp_ident_free(struct lysf_ctx *ctx, struct lysp_ident *ident) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 232 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 233 | lydict_remove(ctx->ctx, ident->name); |
| 234 | FREE_ARRAY(ctx->ctx, ident->iffeatures, lysp_qname_free); |
| 235 | FREE_STRINGS(ctx->ctx, ident->bases); |
| 236 | lydict_remove(ctx->ctx, ident->dsc); |
| 237 | lydict_remove(ctx->ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 238 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 239 | } |
| 240 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 241 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 242 | lysp_restr_free(struct lysf_ctx *ctx, struct lysp_restr *restr) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 243 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 244 | lydict_remove(ctx->ctx, restr->arg.str); |
| 245 | lydict_remove(ctx->ctx, restr->emsg); |
| 246 | lydict_remove(ctx->ctx, restr->eapptag); |
| 247 | lydict_remove(ctx->ctx, restr->dsc); |
| 248 | lydict_remove(ctx->ctx, restr->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 249 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 250 | } |
| 251 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 252 | /** |
| 253 | * @brief Free the parsed type enum item. |
| 254 | * |
| 255 | * @param[in] ctx Free context. |
| 256 | * @param[in] item Parsed schema type enum item to free. Note that the structure itself is not freed. |
| 257 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 258 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 259 | lysp_type_enum_free(struct lysf_ctx *ctx, struct lysp_type_enum *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 260 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 261 | lydict_remove(ctx->ctx, item->name); |
| 262 | lydict_remove(ctx->ctx, item->dsc); |
| 263 | lydict_remove(ctx->ctx, item->ref); |
| 264 | FREE_ARRAY(ctx->ctx, item->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 265 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 266 | } |
| 267 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 268 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 269 | lysp_type_free(struct lysf_ctx *ctx, struct lysp_type *type) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 270 | { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 271 | if (!type) { |
| 272 | return; |
| 273 | } |
| 274 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 275 | lydict_remove(ctx->ctx, type->name); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 276 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 277 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 278 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 279 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 280 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 281 | lyxp_expr_free(ctx->ctx, type->path); |
| 282 | FREE_STRINGS(ctx->ctx, type->bases); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 283 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 284 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 285 | if (type->compiled) { |
| 286 | lysc_type_free(ctx, type->compiled); |
| 287 | } |
| 288 | } |
| 289 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 290 | /** |
| 291 | * @brief Free the parsed typedef structure. |
| 292 | * |
| 293 | * @param[in] ctx Free context. |
| 294 | * @param[in] tpdf Parsed schema typedef structure to free. Note that the structure itself is not freed. |
| 295 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 296 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 297 | lysp_tpdf_free(struct lysf_ctx *ctx, struct lysp_tpdf *tpdf) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 298 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 299 | lydict_remove(ctx->ctx, tpdf->name); |
| 300 | lydict_remove(ctx->ctx, tpdf->units); |
| 301 | lydict_remove(ctx->ctx, tpdf->dflt.str); |
| 302 | lydict_remove(ctx->ctx, tpdf->dsc); |
| 303 | lydict_remove(ctx->ctx, tpdf->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 304 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 305 | |
| 306 | lysp_type_free(ctx, &tpdf->type); |
| 307 | |
| 308 | } |
| 309 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 310 | /** |
| 311 | * @brief Free the parsed grouping structure. |
| 312 | * |
| 313 | * @param[in] ctx Free context. |
| 314 | * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed. |
| 315 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 316 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 317 | lysp_grp_free(struct lysf_ctx *ctx, struct lysp_node_grp *grp) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 318 | { |
| 319 | struct lysp_node *node, *next; |
| 320 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 321 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 322 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) { |
| 323 | lysp_node_free(ctx, node); |
| 324 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 325 | LY_LIST_FOR_SAFE(grp->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 326 | lysp_node_free(ctx, node); |
| 327 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 328 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) { |
| 329 | lysp_node_free(ctx, node); |
| 330 | } |
| 331 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) { |
| 332 | lysp_node_free(ctx, node); |
| 333 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 334 | } |
| 335 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 336 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 337 | lysp_when_free(struct lysf_ctx *ctx, struct lysp_when *when) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 338 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 339 | lydict_remove(ctx->ctx, when->cond); |
| 340 | lydict_remove(ctx->ctx, when->dsc); |
| 341 | lydict_remove(ctx->ctx, when->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 342 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 343 | } |
| 344 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 345 | /** |
| 346 | * @brief Free the parsed augment structure. |
| 347 | * |
| 348 | * @param[in] ctx Free context. |
| 349 | * @param[in] aug Parsed schema augment structure to free. Note that the structure itself is not freed. |
| 350 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 351 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 352 | lysp_augment_free(struct lysf_ctx *ctx, struct lysp_node_augment *aug) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 353 | { |
| 354 | struct lysp_node *node, *next; |
| 355 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 356 | LY_LIST_FOR_SAFE(aug->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 357 | lysp_node_free(ctx, node); |
| 358 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 359 | LY_LIST_FOR_SAFE((struct lysp_node *)aug->actions, next, node) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 360 | lysp_node_free(ctx, node); |
| 361 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 362 | LY_LIST_FOR_SAFE((struct lysp_node *)aug->notifs, next, node) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 363 | lysp_node_free(ctx, node); |
| 364 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 367 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 368 | lysp_deviate_free(struct lysf_ctx *ctx, struct lysp_deviate *d) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 369 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 370 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 371 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 372 | |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 373 | if (!d) { |
| 374 | return; |
| 375 | } |
| 376 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 377 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 378 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 379 | case LYS_DEV_NOT_SUPPORTED: |
| 380 | /* nothing to do */ |
| 381 | break; |
| 382 | case LYS_DEV_ADD: |
| 383 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 384 | lydict_remove(ctx->ctx, add->units); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 385 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 386 | FREE_ARRAY(ctx->ctx, add->uniques, lysp_qname_free); |
| 387 | FREE_ARRAY(ctx->ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 388 | break; |
| 389 | case LYS_DEV_REPLACE: |
| 390 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 391 | lydict_remove(ctx->ctx, rpl->units); |
| 392 | lysp_qname_free(ctx->ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 393 | break; |
| 394 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 395 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 396 | break; |
| 397 | } |
| 398 | } |
| 399 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 400 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 401 | lysp_deviation_free(struct lysf_ctx *ctx, struct lysp_deviation *dev) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 402 | { |
| 403 | struct lysp_deviate *next, *iter; |
| 404 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 405 | lydict_remove(ctx->ctx, dev->nodeid); |
| 406 | lydict_remove(ctx->ctx, dev->dsc); |
| 407 | lydict_remove(ctx->ctx, dev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 408 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 409 | lysp_deviate_free(ctx, iter); |
| 410 | free(iter); |
| 411 | } |
| 412 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 413 | } |
| 414 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 415 | /** |
| 416 | * @brief Free the parsed refine structure. |
| 417 | * |
| 418 | * @param[in] ctx Free context. |
| 419 | * @param[in] ref Parsed schema refine structure to free. Note that the structure itself is not freed. |
| 420 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 421 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 422 | lysp_refine_free(struct lysf_ctx *ctx, struct lysp_refine *ref) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 423 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 424 | lydict_remove(ctx->ctx, ref->nodeid); |
| 425 | lydict_remove(ctx->ctx, ref->dsc); |
| 426 | lydict_remove(ctx->ctx, ref->ref); |
| 427 | FREE_ARRAY(ctx->ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 428 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 429 | lydict_remove(ctx->ctx, ref->presence); |
| 430 | FREE_ARRAY(ctx->ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 431 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 432 | } |
| 433 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 434 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 435 | lysp_node_free(struct lysf_ctx *ctx, struct lysp_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 436 | { |
| 437 | struct lysp_node *child, *next; |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 438 | struct lysp_node_container *cont; |
| 439 | struct lysp_node_leaf *leaf; |
| 440 | struct lysp_node_leaflist *llist; |
| 441 | struct lysp_node_list *list; |
| 442 | struct lysp_node_choice *choice; |
| 443 | struct lysp_node_case *cas; |
| 444 | struct lysp_node_uses *uses; |
| 445 | struct lysp_node_action *act; |
| 446 | struct lysp_node_action_inout *inout; |
| 447 | struct lysp_node_notif *notif; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 448 | struct lysp_restr *musts = lysp_node_musts(node); |
| 449 | struct lysp_when *when = lysp_node_when(node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 450 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 451 | lydict_remove(ctx->ctx, node->name); |
| 452 | lydict_remove(ctx->ctx, node->dsc); |
| 453 | lydict_remove(ctx->ctx, node->ref); |
| 454 | FREE_ARRAY(ctx->ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 455 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 456 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 457 | FREE_MEMBER(ctx, when, lysp_when_free); |
| 458 | FREE_ARRAY(ctx, musts, lysp_restr_free); |
| 459 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 460 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 461 | case LYS_CONTAINER: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 462 | cont = (struct lysp_node_container *)node; |
| 463 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 464 | lydict_remove(ctx->ctx, cont->presence); |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 465 | FREE_ARRAY(ctx, cont->typedefs, lysp_tpdf_free); |
| 466 | if (cont->groupings) { |
| 467 | LY_LIST_FOR_SAFE(&cont->groupings->node, next, child) { |
| 468 | lysp_node_free(ctx, child); |
| 469 | } |
| 470 | } |
| 471 | LY_LIST_FOR_SAFE(cont->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 472 | lysp_node_free(ctx, child); |
| 473 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 474 | if (cont->actions) { |
| 475 | LY_LIST_FOR_SAFE(&cont->actions->node, next, child) { |
| 476 | lysp_node_free(ctx, child); |
| 477 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 478 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 479 | if (cont->notifs) { |
| 480 | LY_LIST_FOR_SAFE(&cont->notifs->node, next, child) { |
| 481 | lysp_node_free(ctx, child); |
| 482 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 483 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 484 | break; |
| 485 | case LYS_LEAF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 486 | leaf = (struct lysp_node_leaf *)node; |
| 487 | |
| 488 | lysp_type_free(ctx, &leaf->type); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 489 | lydict_remove(ctx->ctx, leaf->units); |
| 490 | lydict_remove(ctx->ctx, leaf->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 491 | break; |
| 492 | case LYS_LEAFLIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 493 | llist = (struct lysp_node_leaflist *)node; |
| 494 | |
| 495 | lysp_type_free(ctx, &llist->type); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 496 | lydict_remove(ctx->ctx, llist->units); |
| 497 | FREE_ARRAY(ctx->ctx, llist->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 498 | break; |
| 499 | case LYS_LIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 500 | list = (struct lysp_node_list *)node; |
| 501 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 502 | lydict_remove(ctx->ctx, list->key); |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 503 | FREE_ARRAY(ctx, list->typedefs, lysp_tpdf_free); |
| 504 | if (list->groupings) { |
| 505 | LY_LIST_FOR_SAFE(&list->groupings->node, next, child) { |
| 506 | lysp_node_free(ctx, child); |
| 507 | } |
| 508 | } |
| 509 | LY_LIST_FOR_SAFE(list->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 510 | lysp_node_free(ctx, child); |
| 511 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 512 | if (list->actions) { |
| 513 | LY_LIST_FOR_SAFE(&list->actions->node, next, child) { |
| 514 | lysp_node_free(ctx, child); |
| 515 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 516 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 517 | if (list->notifs) { |
| 518 | LY_LIST_FOR_SAFE(&list->notifs->node, next, child) { |
| 519 | lysp_node_free(ctx, child); |
| 520 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 521 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 522 | FREE_ARRAY(ctx->ctx, list->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 523 | break; |
| 524 | case LYS_CHOICE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 525 | choice = (struct lysp_node_choice *)node; |
| 526 | |
| 527 | LY_LIST_FOR_SAFE(choice->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 528 | lysp_node_free(ctx, child); |
| 529 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 530 | lydict_remove(ctx->ctx, choice->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 531 | break; |
| 532 | case LYS_CASE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 533 | cas = (struct lysp_node_case *)node; |
| 534 | |
| 535 | LY_LIST_FOR_SAFE(cas->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 536 | lysp_node_free(ctx, child); |
| 537 | } |
| 538 | break; |
| 539 | case LYS_ANYDATA: |
| 540 | case LYS_ANYXML: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 541 | /* nothing special to do */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 542 | break; |
| 543 | case LYS_USES: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 544 | uses = (struct lysp_node_uses *)node; |
| 545 | |
| 546 | FREE_ARRAY(ctx, uses->refines, lysp_refine_free); |
| 547 | if (uses->augments) { |
| 548 | LY_LIST_FOR_SAFE(&uses->augments->node, next, child) { |
| 549 | lysp_node_free(ctx, child); |
| 550 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 551 | } |
| 552 | break; |
| 553 | case LYS_RPC: |
| 554 | case LYS_ACTION: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 555 | act = (struct lysp_node_action *)node; |
| 556 | |
| 557 | FREE_ARRAY(ctx, act->typedefs, lysp_tpdf_free); |
| 558 | if (act->groupings) { |
| 559 | LY_LIST_FOR_SAFE(&act->groupings->node, next, child) { |
| 560 | lysp_node_free(ctx, child); |
| 561 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 562 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 563 | if (act->input.nodetype) { |
| 564 | lysp_node_free(ctx, &act->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 565 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 566 | if (act->output.nodetype) { |
| 567 | lysp_node_free(ctx, &act->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 568 | } |
| 569 | break; |
| 570 | case LYS_INPUT: |
| 571 | case LYS_OUTPUT: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 572 | inout = (struct lysp_node_action_inout *)node; |
| 573 | |
| 574 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 575 | if (inout->groupings) { |
| 576 | LY_LIST_FOR_SAFE(&inout->groupings->node, next, child) { |
| 577 | lysp_node_free(ctx, child); |
| 578 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 579 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 580 | LY_LIST_FOR_SAFE(inout->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 581 | lysp_node_free(ctx, child); |
| 582 | } |
| 583 | /* do not free the node, it is never standalone but part of the action node */ |
| 584 | return; |
| 585 | case LYS_NOTIF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 586 | notif = (struct lysp_node_notif *)node; |
| 587 | |
| 588 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 589 | if (notif->groupings) { |
| 590 | LY_LIST_FOR_SAFE(¬if->groupings->node, next, child) { |
| 591 | lysp_node_free(ctx, child); |
| 592 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 593 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 594 | LY_LIST_FOR_SAFE(notif->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 595 | lysp_node_free(ctx, child); |
| 596 | } |
| 597 | break; |
| 598 | case LYS_GROUPING: |
| 599 | lysp_grp_free(ctx, (struct lysp_node_grp *)node); |
| 600 | break; |
| 601 | case LYS_AUGMENT: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 602 | lysp_augment_free(ctx, ((struct lysp_node_augment *)node)); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 603 | break; |
| 604 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 605 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 606 | } |
| 607 | |
| 608 | free(node); |
| 609 | } |
| 610 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 611 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 612 | lysp_module_free(struct lysf_ctx *ctx, struct lysp_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 613 | { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 614 | struct lysp_node *node, *next; |
| 615 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 616 | if (!module) { |
| 617 | return; |
| 618 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 619 | |
| 620 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 621 | 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] | 622 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 623 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 624 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 625 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 626 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 627 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 628 | LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) { |
| 629 | lysp_node_free(ctx, node); |
| 630 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 631 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 632 | lysp_node_free(ctx, node); |
| 633 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 634 | LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) { |
| 635 | lysp_node_free(ctx, node); |
| 636 | } |
| 637 | LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) { |
| 638 | lysp_node_free(ctx, node); |
| 639 | } |
| 640 | LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) { |
| 641 | lysp_node_free(ctx, node); |
| 642 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 643 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 644 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 645 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 646 | if (module->is_submod) { |
| 647 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 648 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 649 | lydict_remove(ctx->ctx, submod->name); |
| 650 | lydict_remove(ctx->ctx, submod->filepath); |
| 651 | lydict_remove(ctx->ctx, submod->prefix); |
| 652 | lydict_remove(ctx->ctx, submod->org); |
| 653 | lydict_remove(ctx->ctx, submod->contact); |
| 654 | lydict_remove(ctx->ctx, submod->dsc); |
| 655 | lydict_remove(ctx->ctx, submod->ref); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 656 | } |
| 657 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 658 | free(module); |
| 659 | } |
| 660 | |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 661 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 662 | lysc_ext_instance_free(struct lysf_ctx *ctx, struct lysc_ext_instance *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 663 | { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 664 | if (ext->def && ext->def->plugin && ext->def->plugin->cfree) { |
| 665 | ext->def->plugin->cfree(ctx->ctx, ext); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 666 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 667 | lydict_remove(ctx->ctx, ext->argument); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 668 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 669 | } |
| 670 | |
| 671 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 672 | lysc_iffeature_free(struct lysf_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 673 | { |
| 674 | LY_ARRAY_FREE(iff->features); |
| 675 | free(iff->expr); |
| 676 | } |
| 677 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 678 | /** |
| 679 | * @brief Free the compiled when structure (decrease refcount) and NULL the provided pointer. |
| 680 | * |
| 681 | * @param[in] ctx Free context. |
| 682 | * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed. |
| 683 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 684 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 685 | lysc_when_free(struct lysf_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 686 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 687 | if (--(*w)->refcount) { |
| 688 | return; |
| 689 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 690 | lyxp_expr_free(ctx->ctx, (*w)->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 691 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, (*w)->prefixes); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 692 | lydict_remove(ctx->ctx, (*w)->dsc); |
| 693 | lydict_remove(ctx->ctx, (*w)->ref); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 694 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 695 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 696 | } |
| 697 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 698 | /** |
| 699 | * @brief Free the compiled must structure. |
| 700 | * |
| 701 | * @param[in] ctx Free context. |
| 702 | * @param[in,out] must Compiled must structure to be freed. |
| 703 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 704 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 705 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 706 | lysc_must_free(struct lysf_ctx *ctx, struct lysc_must *must) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 707 | { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 708 | if (!must) { |
| 709 | return; |
| 710 | } |
| 711 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 712 | lyxp_expr_free(ctx->ctx, must->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 713 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, must->prefixes); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 714 | lydict_remove(ctx->ctx, must->emsg); |
| 715 | lydict_remove(ctx->ctx, must->eapptag); |
| 716 | lydict_remove(ctx->ctx, must->dsc); |
| 717 | lydict_remove(ctx->ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 718 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 719 | } |
| 720 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 721 | /** |
| 722 | * @brief Unlink the identity from all derived identity arrays. |
| 723 | * |
| 724 | * @param[in] ident Identity to unlink. |
| 725 | */ |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 726 | static void |
| 727 | lysc_ident_derived_unlink(const struct lysc_ident *ident) |
| 728 | { |
| 729 | LY_ARRAY_COUNT_TYPE u, v, w; |
| 730 | const struct lysp_submodule *submod; |
Michal Vasko | d84b813 | 2022-03-15 10:45:44 +0100 | [diff] [blame] | 731 | const struct lysp_module *base_pmod = NULL; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 732 | const struct lysp_ident *identp = NULL; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 733 | const struct lys_module *mod, *iter; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 734 | const char *base_name; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 735 | uint32_t i; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 736 | |
| 737 | /* find the parsed identity */ |
| 738 | LY_ARRAY_FOR(ident->module->parsed->identities, u) { |
| 739 | if (ident->module->parsed->identities[u].name == ident->name) { |
| 740 | identp = &ident->module->parsed->identities[u]; |
| 741 | base_pmod = ident->module->parsed; |
| 742 | break; |
| 743 | } |
| 744 | } |
| 745 | if (!identp) { |
| 746 | LY_ARRAY_FOR(ident->module->parsed->includes, v) { |
| 747 | submod = ident->module->parsed->includes[v].submodule; |
| 748 | LY_ARRAY_FOR(submod->identities, u) { |
| 749 | if (submod->identities[u].name == ident->name) { |
| 750 | identp = &submod->identities[u]; |
| 751 | base_pmod = (struct lysp_module *)submod; |
| 752 | break; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | assert(identp); |
| 758 | |
| 759 | /* remove link from all the foreign bases, it may not be there if identity compilation failed */ |
| 760 | LY_ARRAY_FOR(identp->bases, u) { |
| 761 | base_name = strchr(identp->bases[u], ':'); |
| 762 | if (!base_name) { |
| 763 | continue; |
| 764 | } |
| 765 | |
| 766 | /* prefixed identity */ |
| 767 | mod = ly_resolve_prefix(ident->module->ctx, identp->bases[u], base_name - identp->bases[u], LY_VALUE_SCHEMA, |
| 768 | (void *)base_pmod); |
| 769 | if (!mod) { |
| 770 | continue; |
| 771 | } |
| 772 | ++base_name; |
| 773 | |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 774 | i = 0; |
| 775 | while ((iter = ly_ctx_get_module_iter(ident->module->ctx, &i))) { |
| 776 | if (iter == mod) { |
| 777 | break; |
| 778 | } |
| 779 | } |
| 780 | if (!iter) { |
| 781 | /* target module was freed already */ |
| 782 | continue; |
| 783 | } |
| 784 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 785 | /* find the compiled base */ |
| 786 | LY_ARRAY_FOR(mod->identities, v) { |
| 787 | if (!strcmp(mod->identities[v].name, base_name)) { |
| 788 | /* find the derived link */ |
| 789 | LY_ARRAY_FOR(mod->identities[v].derived, w) { |
| 790 | if (mod->identities[v].derived[w] == ident) { |
| 791 | /* remove the link */ |
| 792 | LY_ARRAY_DECREMENT(mod->identities[v].derived); |
Michal Vasko | 3fedda1 | 2022-03-16 09:23:45 +0100 | [diff] [blame] | 793 | if (!LY_ARRAY_COUNT(mod->identities[v].derived)) { |
| 794 | LY_ARRAY_FREE(mod->identities[v].derived); |
| 795 | mod->identities[v].derived = NULL; |
| 796 | } else if (w < LY_ARRAY_COUNT(mod->identities[v].derived)) { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 797 | memmove(mod->identities[v].derived + w, mod->identities[v].derived + w + 1, |
| 798 | (LY_ARRAY_COUNT(mod->identities[v].derived) - w) * sizeof ident); |
| 799 | } |
| 800 | break; |
| 801 | } |
| 802 | } |
| 803 | break; |
| 804 | } |
| 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 809 | /** |
| 810 | * @brief Free the compiled identity structure. |
| 811 | * |
| 812 | * @param[in] ctx Free context. |
| 813 | * @param[in,out] ident Compiled identity structure to be freed. |
| 814 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 815 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 816 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 817 | lysc_ident_free(struct lysf_ctx *ctx, struct lysc_ident *ident) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 818 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 819 | lydict_remove(ctx->ctx, ident->name); |
| 820 | lydict_remove(ctx->ctx, ident->dsc); |
| 821 | lydict_remove(ctx->ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 822 | LY_ARRAY_FREE(ident->derived); |
| 823 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 824 | } |
| 825 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 826 | /** |
| 827 | * @brief Free the compiled range structure. |
| 828 | * |
| 829 | * @param[in] ctx Free context. |
| 830 | * @param[in,out] range Compiled range structure to be freed. |
| 831 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 832 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 833 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 834 | lysc_range_free(struct lysf_ctx *ctx, struct lysc_range *range) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 835 | { |
| 836 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 837 | lydict_remove(ctx->ctx, range->eapptag); |
| 838 | lydict_remove(ctx->ctx, range->emsg); |
| 839 | lydict_remove(ctx->ctx, range->dsc); |
| 840 | lydict_remove(ctx->ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 841 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 842 | } |
| 843 | |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 844 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 845 | lysc_pattern_free(struct lysf_ctx *ctx, struct lysc_pattern **pattern) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 846 | { |
| 847 | if (--(*pattern)->refcount) { |
| 848 | return; |
| 849 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 850 | pcre2_code_free((*pattern)->code); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 851 | lydict_remove(ctx->ctx, (*pattern)->expr); |
| 852 | lydict_remove(ctx->ctx, (*pattern)->eapptag); |
| 853 | lydict_remove(ctx->ctx, (*pattern)->emsg); |
| 854 | lydict_remove(ctx->ctx, (*pattern)->dsc); |
| 855 | lydict_remove(ctx->ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 856 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 857 | free(*pattern); |
| 858 | } |
| 859 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 860 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 861 | lysc_enum_item_free(struct lysf_ctx *ctx, struct lysc_type_bitenum_item *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 862 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 863 | lydict_remove(ctx->ctx, item->name); |
| 864 | lydict_remove(ctx->ctx, item->dsc); |
| 865 | lydict_remove(ctx->ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 866 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 867 | } |
| 868 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 869 | /** |
| 870 | * @brief Free the compiled type structure. |
| 871 | * |
| 872 | * @param[in] ctx Free context. |
| 873 | * @param[in,out] type Pointer to compiled type structure to be freed. |
| 874 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 875 | */ |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 876 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 877 | lysc_type2_free(struct lysf_ctx *ctx, struct lysc_type **type) |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 878 | { |
| 879 | lysc_type_free(ctx, *type); |
| 880 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 881 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 882 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 883 | lysc_type_free(struct lysf_ctx *ctx, struct lysc_type *type) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 884 | { |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 885 | if (!type || (LY_ATOMIC_DEC_BARRIER(type->refcount) > 1)) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 886 | return; |
| 887 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 888 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 889 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 890 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 891 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 892 | break; |
| 893 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 894 | 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] | 895 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 896 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 897 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 898 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 899 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 900 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 901 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 902 | break; |
| 903 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 904 | 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] | 905 | break; |
| 906 | case LY_TYPE_INT8: |
| 907 | case LY_TYPE_UINT8: |
| 908 | case LY_TYPE_INT16: |
| 909 | case LY_TYPE_UINT16: |
| 910 | case LY_TYPE_INT32: |
| 911 | case LY_TYPE_UINT32: |
| 912 | case LY_TYPE_INT64: |
| 913 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 914 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 915 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 916 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 917 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 918 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 919 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 920 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 921 | break; |
| 922 | case LY_TYPE_LEAFREF: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 923 | lyxp_expr_free(ctx->ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 924 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes); |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 925 | lysc_type_free(ctx, ((struct lysc_type_leafref *)type)->realtype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 926 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 927 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 928 | case LY_TYPE_BOOL: |
| 929 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 930 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 931 | /* nothing to do */ |
| 932 | break; |
| 933 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 934 | |
| 935 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 936 | free(type); |
| 937 | } |
| 938 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 939 | /** |
| 940 | * @brief Free the compiled input/output structure. |
| 941 | * |
| 942 | * @param[in] ctx Free context. |
| 943 | * @param[in,out] inout Compiled inout structure to be freed. |
| 944 | * Since the structure is part of the RPC/action structure, it is not freed itself. |
| 945 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 946 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 947 | lysc_node_action_inout_free(struct lysf_ctx *ctx, struct lysc_node_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 948 | { |
| 949 | struct lysc_node *child, *child_next; |
| 950 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 951 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 952 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 953 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 954 | } |
| 955 | } |
| 956 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 957 | /** |
| 958 | * @brief Free the compiled RPC/action structure. |
| 959 | * |
| 960 | * @param[in] ctx Free context. |
| 961 | * @param[in,out] action Compiled RPC/action structure to be freed. |
| 962 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 963 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 964 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 965 | lysc_node_action_free(struct lysf_ctx *ctx, struct lysc_node_action *action) |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 966 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 967 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 968 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 969 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 970 | } |
| 971 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 972 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 973 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 974 | } |
| 975 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 976 | /** |
| 977 | * @brief Free the compiled notification structure. |
| 978 | * |
| 979 | * @param[in] ctx Free context. |
| 980 | * @param[in,out] notif Compiled notification structure to be freed. |
| 981 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 982 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 983 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 984 | lysc_node_notif_free(struct lysf_ctx *ctx, struct lysc_node_notif *notif) |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 985 | { |
| 986 | struct lysc_node *child, *child_next; |
| 987 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 988 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 989 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 990 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 991 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 995 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 996 | lysc_node_container_free(struct lysf_ctx *ctx, struct lysc_node_container *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 997 | { |
| 998 | struct lysc_node *child, *child_next; |
| 999 | |
| 1000 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1001 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1002 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1003 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 1004 | lysc_node_free_(ctx, child); |
| 1005 | } |
| 1006 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 1007 | lysc_node_free_(ctx, child); |
| 1008 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1009 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1010 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1011 | } |
| 1012 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1013 | /** |
| 1014 | * @brief Free the compiled leaf structure. |
| 1015 | * |
| 1016 | * @param[in] ctx Free context. |
| 1017 | * @param[in,out] node Compiled leaf structure to be freed. |
| 1018 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1019 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1020 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1021 | lysc_node_leaf_free(struct lysf_ctx *ctx, struct lysc_node_leaf *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1022 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1023 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1024 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1025 | if (node->type) { |
| 1026 | lysc_type_free(ctx, node->type); |
| 1027 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1028 | lydict_remove(ctx->ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1029 | if (node->dflt) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1030 | node->dflt->realtype->plugin->free(ctx->ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 1031 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1032 | free(node->dflt); |
| 1033 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1034 | } |
| 1035 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1036 | /** |
| 1037 | * @brief Free the compiled leaflist structure. |
| 1038 | * |
| 1039 | * @param[in] ctx Free context. |
| 1040 | * @param[in,out] node Compiled leaflist structure to be freed. |
| 1041 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1042 | */ |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1043 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1044 | lysc_node_leaflist_free(struct lysf_ctx *ctx, struct lysc_node_leaflist *node) |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1045 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1046 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1047 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1048 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1049 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 1050 | if (node->type) { |
| 1051 | lysc_type_free(ctx, node->type); |
| 1052 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1053 | lydict_remove(ctx->ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1054 | LY_ARRAY_FOR(node->dflts, u) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1055 | node->dflts[u]->realtype->plugin->free(ctx->ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 1056 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1057 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1058 | } |
| 1059 | LY_ARRAY_FREE(node->dflts); |
| 1060 | } |
| 1061 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1062 | /** |
| 1063 | * @brief Free the compiled list structure. |
| 1064 | * |
| 1065 | * @param[in] ctx Free context. |
| 1066 | * @param[in,out] node Compiled list structure to be freed. |
| 1067 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1068 | */ |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1069 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1070 | lysc_node_list_free(struct lysf_ctx *ctx, struct lysc_node_list *node) |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1071 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1072 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1073 | struct lysc_node *child, *child_next; |
| 1074 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1075 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1076 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1077 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1078 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1079 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 1080 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1081 | LY_ARRAY_FOR(node->uniques, u) { |
| 1082 | LY_ARRAY_FREE(node->uniques[u]); |
| 1083 | } |
| 1084 | LY_ARRAY_FREE(node->uniques); |
| 1085 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1086 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 1087 | lysc_node_free_(ctx, child); |
| 1088 | } |
| 1089 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 1090 | lysc_node_free_(ctx, child); |
| 1091 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1092 | } |
| 1093 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1094 | /** |
| 1095 | * @brief Free the compiled choice structure. |
| 1096 | * |
| 1097 | * @param[in] ctx Free context. |
| 1098 | * @param[in,out] node Compiled choice structure to be freed. |
| 1099 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1100 | */ |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1101 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1102 | lysc_node_choice_free(struct lysf_ctx *ctx, struct lysc_node_choice *node) |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1103 | { |
| 1104 | struct lysc_node *child, *child_next; |
| 1105 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1106 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1107 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1108 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1109 | } |
| 1110 | } |
| 1111 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1112 | /** |
| 1113 | * @brief Free the compiled case structure. |
| 1114 | * |
| 1115 | * @param[in] ctx Free context. |
| 1116 | * @param[in,out] node Compiled case structure to be freed. |
| 1117 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1118 | */ |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1119 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1120 | lysc_node_case_free(struct lysf_ctx *ctx, struct lysc_node_case *node) |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1121 | { |
| 1122 | struct lysc_node *child, *child_next; |
| 1123 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1124 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1125 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1126 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1127 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1128 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1129 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1130 | /** |
| 1131 | * @brief Free the compiled anyxml/anydata structure. |
| 1132 | * |
| 1133 | * @param[in] ctx Free context. |
| 1134 | * @param[in,out] node Compiled anyxml/anydata structure to be freed. |
| 1135 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1136 | */ |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1137 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1138 | lysc_node_anydata_free(struct lysf_ctx *ctx, struct lysc_node_anydata *node) |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1139 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1140 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1141 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1144 | /** |
| 1145 | * @brief Free the compiled node structure. |
| 1146 | * |
| 1147 | * @param[in] ctx Free context. |
| 1148 | * @param[in,out] node Compiled node structure to be freed. |
| 1149 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1150 | */ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1151 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1152 | lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1153 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1154 | ly_bool inout = 0; |
| 1155 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1156 | /* common part */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1157 | lydict_remove(ctx->ctx, node->name); |
| 1158 | lydict_remove(ctx->ctx, node->dsc); |
| 1159 | lydict_remove(ctx->ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1160 | |
| 1161 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1162 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1163 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1164 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1165 | break; |
| 1166 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1167 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1168 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1169 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1170 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1171 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1172 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1173 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1174 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1175 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1176 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1177 | break; |
| 1178 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1179 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1180 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1181 | case LYS_ANYDATA: |
| 1182 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1183 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1184 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1185 | case LYS_RPC: |
| 1186 | case LYS_ACTION: |
| 1187 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 1188 | break; |
| 1189 | case LYS_INPUT: |
| 1190 | case LYS_OUTPUT: |
| 1191 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 1192 | inout = 1; |
| 1193 | break; |
| 1194 | case LYS_NOTIF: |
| 1195 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 1196 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1197 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1198 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1201 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1202 | |
| 1203 | if (!inout) { |
| 1204 | free(node); |
| 1205 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1206 | } |
| 1207 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1208 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1209 | lysc_node_free(struct lysf_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1210 | { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1211 | struct lysc_node *next, *iter, **child_p; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1212 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1213 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1214 | /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */ |
| 1215 | struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1216 | |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1217 | LY_LIST_FOR_SAFE(inout->child, next, iter) { |
| 1218 | lysc_node_free_(ctx, iter); |
| 1219 | } |
| 1220 | inout->child = NULL; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1221 | return; |
| 1222 | } |
| 1223 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1224 | if (unlink) { |
| 1225 | /* unlink from siblings */ |
| 1226 | if (node->prev->next) { |
| 1227 | node->prev->next = node->next; |
| 1228 | } |
| 1229 | if (node->next) { |
| 1230 | node->next->prev = node->prev; |
| 1231 | } else { |
| 1232 | /* unlinking the last node */ |
| 1233 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1234 | if (node->nodetype == LYS_ACTION) { |
| 1235 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 1236 | } else if (node->nodetype == LYS_NOTIF) { |
| 1237 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 1238 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1239 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1240 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1241 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx->ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1242 | } else if (node->nodetype == LYS_RPC) { |
| 1243 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 1244 | } else if (node->nodetype == LYS_NOTIF) { |
| 1245 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1246 | } else { |
| 1247 | iter = node->module->compiled->data; |
| 1248 | } |
| 1249 | /* update the "last" pointer from the first node */ |
| 1250 | iter->prev = node->prev; |
| 1251 | } |
| 1252 | |
| 1253 | /* unlink from parent */ |
| 1254 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1255 | if (node->nodetype == LYS_ACTION) { |
| 1256 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 1257 | } else if (node->nodetype == LYS_NOTIF) { |
| 1258 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 1259 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1260 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1261 | } |
| 1262 | } else if (node->nodetype == LYS_RPC) { |
| 1263 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 1264 | } else if (node->nodetype == LYS_NOTIF) { |
| 1265 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1266 | } else { |
| 1267 | child_p = &node->module->compiled->data; |
| 1268 | } |
| 1269 | if (child_p && (*child_p == node)) { |
| 1270 | /* the node is the first child */ |
| 1271 | *child_p = node->next; |
| 1272 | } |
| 1273 | } |
| 1274 | |
| 1275 | lysc_node_free_(ctx, node); |
| 1276 | } |
| 1277 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1278 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1279 | lysc_module_free(struct lysf_ctx *ctx, struct lysc_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1280 | { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1281 | struct lysc_node *node, *node_next; |
| 1282 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1283 | if (!module) { |
| 1284 | return; |
| 1285 | } |
| 1286 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1287 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1288 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1289 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1290 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 1291 | lysc_node_free_(ctx, node); |
| 1292 | } |
| 1293 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 1294 | lysc_node_free_(ctx, node); |
| 1295 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1296 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 1297 | |
| 1298 | free(module); |
| 1299 | } |
| 1300 | |
| 1301 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1302 | lys_module_free(struct lysf_ctx *ctx, struct lys_module *module, ly_bool remove_links) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1303 | { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1304 | LY_ARRAY_COUNT_TYPE u; |
| 1305 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1306 | if (!module) { |
| 1307 | return; |
| 1308 | } |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1309 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 1310 | assert(!module->implemented); |
| 1311 | assert(!module->compiled); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1312 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1313 | if (remove_links) { |
| 1314 | /* remove derived identity links */ |
| 1315 | LY_ARRAY_FOR(module->identities, u) { |
| 1316 | lysc_ident_derived_unlink(&module->identities[u]); |
| 1317 | } |
| 1318 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1319 | FREE_ARRAY(ctx, module->identities, lysc_ident_free); |
| 1320 | lysp_module_free(ctx, module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1321 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1322 | LY_ARRAY_FREE(module->augmented_by); |
| 1323 | LY_ARRAY_FREE(module->deviated_by); |
| 1324 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1325 | lydict_remove(ctx->ctx, module->name); |
| 1326 | lydict_remove(ctx->ctx, module->revision); |
| 1327 | lydict_remove(ctx->ctx, module->ns); |
| 1328 | lydict_remove(ctx->ctx, module->prefix); |
| 1329 | lydict_remove(ctx->ctx, module->filepath); |
| 1330 | lydict_remove(ctx->ctx, module->org); |
| 1331 | lydict_remove(ctx->ctx, module->contact); |
| 1332 | lydict_remove(ctx->ctx, module->dsc); |
| 1333 | lydict_remove(ctx->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1334 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1335 | free(module); |
| 1336 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 1337 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1338 | void |
| 1339 | lysf_ctx_erase(struct lysf_ctx *ctx) |
| 1340 | { |
| 1341 | struct lysc_ext *ext; |
| 1342 | uint32_t i; |
| 1343 | |
| 1344 | for (i = 0; i < ctx->ext_set.count; ++i) { |
| 1345 | ext = ctx->ext_set.objs[i]; |
| 1346 | |
| 1347 | lydict_remove(ctx->ctx, ext->name); |
| 1348 | lydict_remove(ctx->ctx, ext->argname); |
| 1349 | free(ext); |
| 1350 | } |
| 1351 | ly_set_erase(&ctx->ext_set, NULL); |
| 1352 | } |
| 1353 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 1354 | LIBYANG_API_DEF void |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1355 | lyplg_ext_pfree_instance_substatements(const struct ly_ctx *ctx, struct lysp_ext_substmt *substmts) |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1356 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1357 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1358 | struct lysf_ctx fctx = {.ctx = (struct ly_ctx *)ctx}; |
| 1359 | ly_bool node_free; |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1360 | |
| 1361 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1362 | if (!substmts[u].storage) { |
| 1363 | continue; |
| 1364 | } |
| 1365 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1366 | switch (substmts[u].stmt) { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1367 | case LY_STMT_NOTIFICATION: |
| 1368 | case LY_STMT_INPUT: |
| 1369 | case LY_STMT_OUTPUT: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1370 | case LY_STMT_ACTION: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1371 | case LY_STMT_RPC: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1372 | case LY_STMT_ANYDATA: |
| 1373 | case LY_STMT_ANYXML: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1374 | case LY_STMT_AUGMENT: |
| 1375 | case LY_STMT_CASE: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1376 | case LY_STMT_CHOICE: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1377 | case LY_STMT_CONTAINER: |
| 1378 | case LY_STMT_GROUPING: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1379 | case LY_STMT_LEAF: |
| 1380 | case LY_STMT_LEAF_LIST: |
| 1381 | case LY_STMT_LIST: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1382 | case LY_STMT_USES: { |
| 1383 | struct lysp_node *child, *child_next; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1384 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1385 | LY_LIST_FOR_SAFE(*((struct lysp_node **)substmts[u].storage), child_next, child) { |
| 1386 | node_free = (child->nodetype & (LYS_INPUT | LYS_OUTPUT)) ? 1 : 0; |
| 1387 | lysp_node_free(&fctx, child); |
| 1388 | if (node_free) { |
| 1389 | free(child); |
| 1390 | } |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1391 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1392 | *((struct lysc_node **)substmts[u].storage) = NULL; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1393 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1394 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1395 | case LY_STMT_BASE: |
| 1396 | /* multiple strings */ |
| 1397 | FREE_ARRAY(ctx, **(const char ***)substmts[u].storage, lydict_remove); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1398 | break; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1399 | |
| 1400 | case LY_STMT_BIT: |
| 1401 | case LY_STMT_ENUM: |
| 1402 | /* single enum */ |
| 1403 | lysp_type_enum_free(&fctx, *(struct lysp_type_enum **)substmts[u].storage); |
| 1404 | break; |
| 1405 | |
| 1406 | case LY_STMT_DEVIATE: |
| 1407 | /* single deviate */ |
| 1408 | lysp_deviate_free(&fctx, *(struct lysp_deviate **)substmts[u].storage); |
| 1409 | break; |
| 1410 | |
| 1411 | case LY_STMT_DEVIATION: |
| 1412 | /* single deviation */ |
| 1413 | lysp_deviation_free(&fctx, *(struct lysp_deviation **)substmts[u].storage); |
| 1414 | break; |
| 1415 | |
| 1416 | case LY_STMT_EXTENSION: |
| 1417 | /* single extension */ |
| 1418 | lysp_ext_free(&fctx, *(struct lysp_ext **)substmts[u].storage); |
| 1419 | break; |
| 1420 | |
| 1421 | case LY_STMT_EXTENSION_INSTANCE: |
| 1422 | /* multiple extension instances */ |
| 1423 | FREE_ARRAY(&fctx, *(struct lysp_ext_instance **)substmts[u].storage, lysp_ext_instance_free); |
| 1424 | break; |
| 1425 | |
| 1426 | case LY_STMT_FEATURE: |
| 1427 | /* multiple features */ |
| 1428 | FREE_ARRAY(&fctx, *(struct lysp_feature **)substmts[u].storage, lysp_feature_free); |
| 1429 | break; |
| 1430 | |
| 1431 | case LY_STMT_IDENTITY: |
| 1432 | /* multiple identities */ |
| 1433 | FREE_ARRAY(&fctx, *(struct lysp_ident **)substmts[u].storage, lysp_ident_free); |
| 1434 | break; |
| 1435 | |
| 1436 | case LY_STMT_IMPORT: |
| 1437 | /* multiple imports */ |
| 1438 | FREE_ARRAY(&fctx, *(struct lysp_import **)substmts[u].storage, lysp_import_free); |
| 1439 | break; |
| 1440 | |
| 1441 | case LY_STMT_INCLUDE: |
| 1442 | /* multiple includes */ |
| 1443 | FREE_ARRAY(&fctx, *(struct lysp_include **)substmts[u].storage, lysp_include_free); |
| 1444 | break; |
| 1445 | |
| 1446 | case LY_STMT_REFINE: |
| 1447 | /* multiple refines */ |
| 1448 | FREE_ARRAY(&fctx, *(struct lysp_refine **)substmts[u].storage, lysp_refine_free); |
| 1449 | break; |
| 1450 | |
| 1451 | case LY_STMT_REVISION: |
| 1452 | /* multiple revisions */ |
| 1453 | FREE_ARRAY(&fctx, *(struct lysp_revision **)substmts[u].storage, lysp_revision_free); |
| 1454 | break; |
| 1455 | |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1456 | case LY_STMT_CONFIG: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1457 | case LY_STMT_FRACTION_DIGITS: |
| 1458 | case LY_STMT_MANDATORY: |
| 1459 | case LY_STMT_MAX_ELEMENTS: |
| 1460 | case LY_STMT_MIN_ELEMENTS: |
| 1461 | case LY_STMT_ORDERED_BY: |
| 1462 | case LY_STMT_POSITION: |
| 1463 | case LY_STMT_REQUIRE_INSTANCE: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1464 | case LY_STMT_STATUS: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1465 | case LY_STMT_VALUE: |
| 1466 | case LY_STMT_YANG_VERSION: |
| 1467 | case LY_STMT_YIN_ELEMENT: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1468 | /* nothing to do */ |
| 1469 | break; |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1470 | |
| 1471 | case LY_STMT_ARGUMENT: |
| 1472 | case LY_STMT_BELONGS_TO: |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1473 | case LY_STMT_CONTACT: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1474 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1475 | case LY_STMT_ERROR_APP_TAG: |
| 1476 | case LY_STMT_ERROR_MESSAGE: |
| 1477 | case LY_STMT_KEY: |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1478 | case LY_STMT_MODIFIER: |
| 1479 | case LY_STMT_NAMESPACE: |
| 1480 | case LY_STMT_ORGANIZATION: |
| 1481 | case LY_STMT_PREFIX: |
| 1482 | case LY_STMT_PRESENCE: |
| 1483 | case LY_STMT_REFERENCE: |
| 1484 | case LY_STMT_REVISION_DATE: |
| 1485 | case LY_STMT_UNITS: |
| 1486 | /* single string */ |
| 1487 | lydict_remove(ctx, *(const char **)substmts[u].storage); |
| 1488 | break; |
| 1489 | |
| 1490 | case LY_STMT_LENGTH: |
| 1491 | case LY_STMT_MUST: |
| 1492 | case LY_STMT_PATTERN: |
| 1493 | case LY_STMT_RANGE: |
| 1494 | /* multiple restrictions */ |
| 1495 | FREE_ARRAY(&fctx, *(struct lysp_restr **)substmts[u].storage, lysp_restr_free); |
| 1496 | break; |
| 1497 | |
| 1498 | case LY_STMT_WHEN: |
| 1499 | /* multiple whens */ |
| 1500 | FREE_ARRAY(&fctx, *(struct lysp_when **)substmts[u].storage, lysp_when_free); |
| 1501 | break; |
| 1502 | |
| 1503 | case LY_STMT_PATH: |
| 1504 | /* single expression */ |
| 1505 | lyxp_expr_free(ctx, *(struct lyxp_expr **)substmts[u].storage); |
| 1506 | break; |
| 1507 | |
| 1508 | case LY_STMT_DEFAULT: |
| 1509 | case LY_STMT_IF_FEATURE: |
| 1510 | case LY_STMT_UNIQUE: |
| 1511 | /* multiple qnames */ |
| 1512 | FREE_ARRAY(ctx, *(struct lysp_qname **)substmts[u].storage, lysp_qname_free); |
| 1513 | break; |
| 1514 | |
| 1515 | case LY_STMT_TYPEDEF: |
| 1516 | /* multiple typedefs */ |
| 1517 | FREE_ARRAY(&fctx, *(struct lysp_tpdf **)substmts[u].storage, lysp_tpdf_free); |
| 1518 | break; |
| 1519 | |
| 1520 | case LY_STMT_TYPE: { |
| 1521 | /* single type */ |
| 1522 | struct lysp_type **type_p = substmts[u].storage; |
| 1523 | |
| 1524 | lysp_type_free(&fctx, *type_p); |
| 1525 | free(*type_p); |
| 1526 | break; |
| 1527 | } |
| 1528 | case LY_STMT_MODULE: |
| 1529 | case LY_STMT_SUBMODULE: |
| 1530 | /* single (sub)module */ |
| 1531 | lysp_module_free(&fctx, *(struct lysp_module **)substmts[u].storage); |
| 1532 | break; |
| 1533 | |
| 1534 | default: |
| 1535 | LOGINT(ctx); |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | LY_ARRAY_FREE(substmts); |
| 1540 | } |
| 1541 | |
| 1542 | LIBYANG_API_DEF void |
| 1543 | lyplg_ext_cfree_instance_substatements(const struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
| 1544 | { |
| 1545 | LY_ARRAY_COUNT_TYPE u; |
| 1546 | struct lysf_ctx fctx = {.ctx = (struct ly_ctx *)ctx}; |
| 1547 | ly_bool node_free; |
| 1548 | |
| 1549 | LY_ARRAY_FOR(substmts, u) { |
| 1550 | if (!substmts[u].storage) { |
| 1551 | continue; |
| 1552 | } |
| 1553 | |
| 1554 | switch (substmts[u].stmt) { |
| 1555 | case LY_STMT_NOTIFICATION: |
| 1556 | case LY_STMT_INPUT: |
| 1557 | case LY_STMT_OUTPUT: |
| 1558 | case LY_STMT_ACTION: |
| 1559 | case LY_STMT_RPC: |
| 1560 | case LY_STMT_ANYDATA: |
| 1561 | case LY_STMT_ANYXML: |
| 1562 | case LY_STMT_CASE: |
| 1563 | case LY_STMT_CHOICE: |
| 1564 | case LY_STMT_CONTAINER: |
| 1565 | case LY_STMT_LEAF: |
| 1566 | case LY_STMT_LEAF_LIST: |
| 1567 | case LY_STMT_LIST: { |
| 1568 | struct lysc_node *child, *child_next; |
| 1569 | |
| 1570 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
| 1571 | node_free = (child->nodetype & (LYS_INPUT | LYS_OUTPUT)) ? 1 : 0; |
| 1572 | lysc_node_free_(&fctx, child); |
| 1573 | if (node_free) { |
| 1574 | free(child); |
| 1575 | } |
| 1576 | } |
| 1577 | *((struct lysc_node **)substmts[u].storage) = NULL; |
| 1578 | break; |
| 1579 | } |
| 1580 | case LY_STMT_USES: |
| 1581 | case LY_STMT_CONFIG: |
| 1582 | case LY_STMT_FRACTION_DIGITS: |
| 1583 | case LY_STMT_MANDATORY: |
| 1584 | case LY_STMT_MAX_ELEMENTS: |
| 1585 | case LY_STMT_MIN_ELEMENTS: |
| 1586 | case LY_STMT_ORDERED_BY: |
| 1587 | case LY_STMT_POSITION: |
| 1588 | case LY_STMT_REQUIRE_INSTANCE: |
| 1589 | case LY_STMT_STATUS: |
| 1590 | case LY_STMT_VALUE: |
| 1591 | /* nothing to do */ |
| 1592 | break; |
| 1593 | |
| 1594 | case LY_STMT_ARGUMENT: |
| 1595 | case LY_STMT_CONTACT: |
| 1596 | case LY_STMT_DESCRIPTION: |
| 1597 | case LY_STMT_ERROR_APP_TAG: |
| 1598 | case LY_STMT_ERROR_MESSAGE: |
| 1599 | case LY_STMT_KEY: |
| 1600 | case LY_STMT_MODIFIER: |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1601 | case LY_STMT_NAMESPACE: |
| 1602 | case LY_STMT_ORGANIZATION: |
| 1603 | case LY_STMT_PRESENCE: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1604 | case LY_STMT_REFERENCE: |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1605 | case LY_STMT_UNITS: { |
| 1606 | /* single item */ |
| 1607 | const char *str = *((const char **)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1608 | |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1609 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1610 | break; |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1611 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1612 | case LY_STMT_BIT: |
| 1613 | case LY_STMT_ENUM: { |
| 1614 | /* sized array */ |
| 1615 | struct lysc_type_bitenum_item *items = *((struct lysc_type_bitenum_item **)substmts[u].storage); |
| 1616 | |
| 1617 | FREE_ARRAY(&fctx, items, lysc_enum_item_free); |
| 1618 | break; |
| 1619 | } |
| 1620 | case LY_STMT_LENGTH: |
| 1621 | case LY_STMT_RANGE: { |
| 1622 | /* single item */ |
| 1623 | struct lysc_range *range = *((struct lysc_range **)substmts[u].storage); |
| 1624 | |
| 1625 | lysc_range_free(&fctx, range); |
| 1626 | break; |
| 1627 | } |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1628 | case LY_STMT_MUST: { |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1629 | /* sized array */ |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1630 | struct lysc_must *musts = *((struct lysc_must **)substmts[u].storage); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1631 | |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1632 | FREE_ARRAY(&fctx, musts, lysc_must_free); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1633 | break; |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1634 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1635 | case LY_STMT_WHEN: |
| 1636 | /* single item, expects a pointer */ |
| 1637 | lysc_when_free(&fctx, substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1638 | break; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1639 | |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1640 | case LY_STMT_PATTERN: { |
| 1641 | /* sized array of pointers */ |
| 1642 | struct lysc_pattern **patterns = *((struct lysc_pattern ***)substmts[u].storage); |
| 1643 | |
| 1644 | FREE_ARRAY(&fctx, patterns, lysc_pattern_free); |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1645 | break; |
| 1646 | } |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1647 | case LY_STMT_TYPE: { |
| 1648 | /* single item */ |
| 1649 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1650 | |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1651 | lysc_type_free(&fctx, type); |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1652 | break; |
Michal Vasko | 9c3556a | 2022-10-06 16:08:47 +0200 | [diff] [blame] | 1653 | } |
Michal Vasko | 193dacd | 2022-10-13 08:43:05 +0200 | [diff] [blame] | 1654 | case LY_STMT_IDENTITY: { |
| 1655 | /* sized array */ |
| 1656 | struct lysc_ident *idents = *((struct lysc_ident **)substmts[u].storage); |
| 1657 | |
| 1658 | FREE_ARRAY(&fctx, idents, lysc_ident_free); |
| 1659 | break; |
| 1660 | } |
| 1661 | case LY_STMT_EXTENSION_INSTANCE: { |
| 1662 | /* sized array */ |
| 1663 | struct lysc_ext_instance *exts = *((struct lysc_ext_instance **)substmts[u].storage); |
| 1664 | |
| 1665 | FREE_ARRAY(&fctx, exts, lysc_ext_instance_free); |
| 1666 | break; |
| 1667 | } |
| 1668 | case LY_STMT_AUGMENT: |
| 1669 | case LY_STMT_BASE: |
| 1670 | case LY_STMT_BELONGS_TO: |
| 1671 | case LY_STMT_DEFAULT: |
| 1672 | case LY_STMT_DEVIATE: |
| 1673 | case LY_STMT_DEVIATION: |
| 1674 | case LY_STMT_EXTENSION: |
| 1675 | case LY_STMT_FEATURE: |
| 1676 | case LY_STMT_GROUPING: |
| 1677 | case LY_STMT_IF_FEATURE: |
| 1678 | case LY_STMT_IMPORT: |
| 1679 | case LY_STMT_INCLUDE: |
| 1680 | case LY_STMT_MODULE: |
| 1681 | case LY_STMT_PATH: |
| 1682 | case LY_STMT_PREFIX: |
| 1683 | case LY_STMT_REFINE: |
| 1684 | case LY_STMT_REVISION: |
| 1685 | case LY_STMT_REVISION_DATE: |
| 1686 | case LY_STMT_SUBMODULE: |
| 1687 | case LY_STMT_TYPEDEF: |
| 1688 | case LY_STMT_UNIQUE: |
| 1689 | case LY_STMT_YANG_VERSION: |
| 1690 | case LY_STMT_YIN_ELEMENT: |
| 1691 | /* it is not possible to compile these statements */ |
| 1692 | break; |
| 1693 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1694 | default: |
| 1695 | LOGINT(ctx); |
| 1696 | } |
| 1697 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1698 | |
| 1699 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1700 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1701 | |
| 1702 | void |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1703 | lysp_yang_ctx_free(struct lysp_yang_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1704 | { |
| 1705 | if (ctx) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1706 | if (ctx->main_ctx == (struct lysp_ctx *)ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1707 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1708 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1709 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1710 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1711 | ly_set_erase(&ctx->ext_inst, NULL); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1712 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1713 | if (!ctx->parsed_mods->count) { |
| 1714 | ly_set_free(ctx->parsed_mods, NULL); |
| 1715 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1716 | free(ctx); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | void |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1721 | lysp_yin_ctx_free(struct lysp_yin_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1722 | { |
| 1723 | if (ctx) { |
Michal Vasko | d0625d7 | 2022-10-06 15:02:50 +0200 | [diff] [blame] | 1724 | if (ctx->main_ctx == (struct lysp_ctx *)ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1725 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1726 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1727 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1728 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | c0c64ae | 2022-10-06 10:15:23 +0200 | [diff] [blame] | 1729 | ly_set_erase(&ctx->ext_inst, NULL); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1730 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1731 | if (!ctx->parsed_mods->count) { |
| 1732 | ly_set_free(ctx->parsed_mods, NULL); |
| 1733 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1734 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1735 | free(ctx); |
| 1736 | } |
| 1737 | } |