blob: 34f1a22f159d72815a1eff3f5669c613911b0235 [file] [log] [blame]
Radek Krejci19a96102018-11-15 13:38:09 +01001/**
Radek Krejcie7b95092019-05-15 11:03:07 +02002 * @file tree_schema_free.c
Radek Krejci19a96102018-11-15 13:38:09 +01003 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskoc636ea42022-09-16 10:20:31 +02004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejcie7b95092019-05-15 11:03:07 +02005 * @brief Freeing functions for schema tree structures.
Radek Krejci19a96102018-11-15 13:38:09 +01006 *
Michal Vaskoc636ea42022-09-16 10:20:31 +02007 * Copyright (c) 2019 - 2022 CESNET, z.s.p.o.
Radek Krejci19a96102018-11-15 13:38:09 +01008 *
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 Vaskoc636ea42022-09-16 10:20:31 +020016#include "tree_schema_free.h"
17
Michal Vaskoee757602021-06-10 14:38:19 +020018#include <assert.h>
Radek Krejcie7b95092019-05-15 11:03:07 +020019#include <stdlib.h>
20
Radek Krejci535ea9f2020-05-29 16:01:05 +020021#include "common.h"
Michal Vasko69730152020-10-09 16:30:07 +020022#include "compat.h"
Radek Krejci77114102021-03-10 15:21:57 +010023#include "dict.h"
Radek Krejci47fab892020-11-05 17:02:41 +010024#include "log.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020025#include "plugins_exts.h"
26#include "plugins_types.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020027#include "tree.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020028#include "tree_data.h"
Michal Vaskofc2cd072021-02-24 13:17:17 +010029#include "tree_data_internal.h"
Radek Krejci859a15a2021-03-05 20:56:59 +010030#include "tree_edit.h"
Radek Krejcie7b95092019-05-15 11:03:07 +020031#include "tree_schema.h"
Radek Krejci19a96102018-11-15 13:38:09 +010032#include "tree_schema_internal.h"
Radek Krejci535ea9f2020-05-29 16:01:05 +020033#include "xml.h"
Radek Krejci19a96102018-11-15 13:38:09 +010034#include "xpath.h"
35
Michal Vaskoc636ea42022-09-16 10:20:31 +020036static void lysc_extension_free(struct lysf_ctx *ctx, struct lysc_ext **ext);
37static void lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node);
Radek Krejci19a96102018-11-15 13:38:09 +010038
Michal Vaskoc636ea42022-09-16 10:20:31 +020039void
40lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname)
41{
42 if (qname) {
43 lydict_remove(ctx, qname->str);
44 }
45}
46
47/**
48 * @brief Free the parsed generic statement structure.
49 *
50 * @param[in] ctx libyang context.
51 * @param[in] grp Parsed schema statement structure to free. Note that the structure itself is not freed.
52 */
Radek Krejci19a96102018-11-15 13:38:09 +010053static void
54lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt)
55{
56 struct lysp_stmt *child, *next;
57
Michal Vaskoe180ed02021-02-05 16:31:20 +010058 lydict_remove(ctx, stmt->stmt);
59 lydict_remove(ctx, stmt->arg);
Michal Vaskofc2cd072021-02-24 13:17:17 +010060 ly_free_prefix_data(stmt->format, stmt->prefix_data);
Radek Krejci19a96102018-11-15 13:38:09 +010061
62 LY_LIST_FOR_SAFE(stmt->child, next, child) {
63 lysp_stmt_free(ctx, child);
64 }
65
66 free(stmt);
67}
68
Michal Vaskoc636ea42022-09-16 10:20:31 +020069void
70lysp_ext_instance_free(struct lysf_ctx *ctx, struct lysp_ext_instance *ext)
Radek Krejci19a96102018-11-15 13:38:09 +010071{
72 struct lysp_stmt *stmt, *next;
aPiecek60d9d672021-04-27 15:49:57 +020073 struct lysp_node *node, *next_node;
Radek Krejci19a96102018-11-15 13:38:09 +010074
Michal Vaskoc636ea42022-09-16 10:20:31 +020075 lydict_remove(ctx->ctx, ext->name);
76 lydict_remove(ctx->ctx, ext->argument);
Michal Vaskofc2cd072021-02-24 13:17:17 +010077 ly_free_prefix_data(ext->format, ext->prefix_data);
aPiecek60d9d672021-04-27 15:49:57 +020078 LY_LIST_FOR_SAFE(ext->parsed, next_node, node) {
79 lysp_node_free(ctx, node);
80 }
Radek Krejci19a96102018-11-15 13:38:09 +010081
82 LY_LIST_FOR_SAFE(ext->child, next, stmt) {
Michal Vaskoc636ea42022-09-16 10:20:31 +020083 lysp_stmt_free(ctx->ctx, stmt);
Radek Krejci19a96102018-11-15 13:38:09 +010084 }
85}
86
Michal Vaskoc636ea42022-09-16 10:20:31 +020087/**
88 * @brief Free the parsed import structure.
89 *
90 * @param[in] ctx Free context.
91 * @param[in] import Parsed schema import structure to free. Note that the structure itself is not freed.
92 */
Michal Vasko12ef5362022-09-16 15:13:58 +020093static void
Michal Vaskoc636ea42022-09-16 10:20:31 +020094lysp_import_free(struct lysf_ctx *ctx, struct lysp_import *import)
Radek Krejci19a96102018-11-15 13:38:09 +010095{
96 /* imported module is freed directly from the context's list */
Michal Vaskoc636ea42022-09-16 10:20:31 +020097 lydict_remove(ctx->ctx, import->name);
98 lydict_remove(ctx->ctx, import->prefix);
99 lydict_remove(ctx->ctx, import->dsc);
100 lydict_remove(ctx->ctx, import->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100101 FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free);
102}
103
Radek Krejci771928a2021-01-19 13:42:36 +0100104/**
105 * @brief Common function to erase include record in main module and submodule.
106 *
107 * There is a difference since the main module is expected to have the complete list if the included submodules and
108 * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include
109 * record are freed only from main module's records.
110 *
111 * @param[in] ctx libyang context
112 * @param[in] include The include record to be erased, the record itself is not freed.
113 * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule
114 * is supposed to be freed.
115 */
116static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200117lysp_include_free_(struct lysf_ctx *ctx, struct lysp_include *include, ly_bool main_module)
Radek Krejci19a96102018-11-15 13:38:09 +0100118{
Radek Krejci771928a2021-01-19 13:42:36 +0100119 if (main_module && include->submodule) {
Michal Vaskoc636ea42022-09-16 10:20:31 +0200120 lysp_module_free(ctx, (struct lysp_module *)include->submodule);
Radek Krejci19a96102018-11-15 13:38:09 +0100121 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200122 lydict_remove(ctx->ctx, include->name);
123 lydict_remove(ctx->ctx, include->dsc);
124 lydict_remove(ctx->ctx, include->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100125 FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free);
126}
127
Michal Vaskoc636ea42022-09-16 10:20:31 +0200128/**
129 * @brief Free the parsed include structure of a submodule.
130 *
131 * @param[in] ctx Free context.
132 * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed.
133 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200134static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200135lysp_include_free_submodule(struct lysf_ctx *ctx, struct lysp_include *include)
Radek Krejci771928a2021-01-19 13:42:36 +0100136{
Michal Vaskoa0a498b2021-09-22 12:17:48 +0200137 lysp_include_free_(ctx, include, 0);
Radek Krejci771928a2021-01-19 13:42:36 +0100138}
139
Michal Vaskoc636ea42022-09-16 10:20:31 +0200140/**
141 * @brief Free the parsed include structure of a module.
142 *
143 * @param[in] ctx Free context.
144 * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed.
145 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200146static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200147lysp_include_free(struct lysf_ctx *ctx, struct lysp_include *include)
Radek Krejci771928a2021-01-19 13:42:36 +0100148{
Michal Vaskoa0a498b2021-09-22 12:17:48 +0200149 lysp_include_free_(ctx, include, 1);
Radek Krejci771928a2021-01-19 13:42:36 +0100150}
151
Michal Vaskoc636ea42022-09-16 10:20:31 +0200152/**
153 * @brief Free the parsed revision structure.
154 *
155 * @param[in] ctx Free context.
156 * @param[in] rev Parsed schema revision structure to free. Note that the structure itself is not freed.
157 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200158static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200159lysp_revision_free(struct lysf_ctx *ctx, struct lysp_revision *rev)
Radek Krejci19a96102018-11-15 13:38:09 +0100160{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200161 lydict_remove(ctx->ctx, rev->dsc);
162 lydict_remove(ctx->ctx, rev->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100163 FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free);
164}
165
Michal Vaskoc636ea42022-09-16 10:20:31 +0200166/**
167 * @brief Free the parsed ext structure.
168 *
169 * @param[in] ctx Free context.
170 * @param[in] ext Parsed schema ext structure to free. Note that the structure itself is not freed.
171 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200172static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200173lysp_ext_free(struct lysf_ctx *ctx, struct lysp_ext *ext)
Radek Krejci19a96102018-11-15 13:38:09 +0100174{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200175 lydict_remove(ctx->ctx, ext->name);
176 lydict_remove(ctx->ctx, ext->argname);
177 lydict_remove(ctx->ctx, ext->dsc);
178 lydict_remove(ctx->ctx, ext->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100179 FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free);
Michal Vasko5fe75f12020-03-02 13:52:37 +0100180 if (ext->compiled) {
181 lysc_extension_free(ctx, &ext->compiled);
182 }
Radek Krejci19a96102018-11-15 13:38:09 +0100183}
184
Michal Vaskoc636ea42022-09-16 10:20:31 +0200185/**
186 * @brief Free the parsed feature structure.
187 *
188 * @param[in] ctx Free context.
189 * @param[in] feat Parsed schema feature structure to free. Note that the structure itself is not freed.
190 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200191static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200192lysp_feature_free(struct lysf_ctx *ctx, struct lysp_feature *feat)
Radek Krejci19a96102018-11-15 13:38:09 +0100193{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200194 lydict_remove(ctx->ctx, feat->name);
195 FREE_ARRAY(ctx->ctx, feat->iffeatures, lysp_qname_free);
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100196 FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free);
197 LY_ARRAY_FREE(feat->depfeatures);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200198 lydict_remove(ctx->ctx, feat->dsc);
199 lydict_remove(ctx->ctx, feat->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100200 FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free);
201}
202
Michal Vaskoc636ea42022-09-16 10:20:31 +0200203/**
204 * @brief Free the parsed identity structure.
205 *
206 * @param[in] ctx Free context.
207 * @param[in] ident Parsed schema identity structure to free. Note that the structure itself is not freed.
208 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200209static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200210lysp_ident_free(struct lysf_ctx *ctx, struct lysp_ident *ident)
Radek Krejci19a96102018-11-15 13:38:09 +0100211{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200212 lydict_remove(ctx->ctx, ident->name);
213 FREE_ARRAY(ctx->ctx, ident->iffeatures, lysp_qname_free);
214 FREE_STRINGS(ctx->ctx, ident->bases);
215 lydict_remove(ctx->ctx, ident->dsc);
216 lydict_remove(ctx->ctx, ident->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100217 FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free);
218}
219
Michal Vasko7f45cf22020-10-01 12:49:44 +0200220void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200221lysp_restr_free(struct lysf_ctx *ctx, struct lysp_restr *restr)
Radek Krejci19a96102018-11-15 13:38:09 +0100222{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200223 lydict_remove(ctx->ctx, restr->arg.str);
224 lydict_remove(ctx->ctx, restr->emsg);
225 lydict_remove(ctx->ctx, restr->eapptag);
226 lydict_remove(ctx->ctx, restr->dsc);
227 lydict_remove(ctx->ctx, restr->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100228 FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free);
229}
230
Michal Vaskoc636ea42022-09-16 10:20:31 +0200231/**
232 * @brief Free the parsed type enum item.
233 *
234 * @param[in] ctx Free context.
235 * @param[in] item Parsed schema type enum item to free. Note that the structure itself is not freed.
236 */
Radek Krejci19a96102018-11-15 13:38:09 +0100237static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200238lysp_type_enum_free(struct lysf_ctx *ctx, struct lysp_type_enum *item)
Radek Krejci19a96102018-11-15 13:38:09 +0100239{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200240 lydict_remove(ctx->ctx, item->name);
241 lydict_remove(ctx->ctx, item->dsc);
242 lydict_remove(ctx->ctx, item->ref);
243 FREE_ARRAY(ctx->ctx, item->iffeatures, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100244 FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free);
245}
246
David Sedlák32488102019-07-15 17:44:10 +0200247void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200248lysp_type_free(struct lysf_ctx *ctx, struct lysp_type *type)
Radek Krejci19a96102018-11-15 13:38:09 +0100249{
Michal Vaskoedb0fa52022-10-04 10:36:00 +0200250 if (!type) {
251 return;
252 }
253
Michal Vaskoc636ea42022-09-16 10:20:31 +0200254 lydict_remove(ctx->ctx, type->name);
Radek Krejci19a96102018-11-15 13:38:09 +0100255 FREE_MEMBER(ctx, type->range, lysp_restr_free);
256 FREE_MEMBER(ctx, type->length, lysp_restr_free);
257 FREE_ARRAY(ctx, type->patterns, lysp_restr_free);
258 FREE_ARRAY(ctx, type->enums, lysp_type_enum_free);
259 FREE_ARRAY(ctx, type->bits, lysp_type_enum_free);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200260 lyxp_expr_free(ctx->ctx, type->path);
261 FREE_STRINGS(ctx->ctx, type->bases);
Radek Krejci19a96102018-11-15 13:38:09 +0100262 FREE_ARRAY(ctx, type->types, lysp_type_free);
263 FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free);
264 if (type->compiled) {
265 lysc_type_free(ctx, type->compiled);
266 }
267}
268
Michal Vaskoc636ea42022-09-16 10:20:31 +0200269/**
270 * @brief Free the parsed typedef structure.
271 *
272 * @param[in] ctx Free context.
273 * @param[in] tpdf Parsed schema typedef structure to free. Note that the structure itself is not freed.
274 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200275static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200276lysp_tpdf_free(struct lysf_ctx *ctx, struct lysp_tpdf *tpdf)
Radek Krejci19a96102018-11-15 13:38:09 +0100277{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200278 lydict_remove(ctx->ctx, tpdf->name);
279 lydict_remove(ctx->ctx, tpdf->units);
280 lydict_remove(ctx->ctx, tpdf->dflt.str);
281 lydict_remove(ctx->ctx, tpdf->dsc);
282 lydict_remove(ctx->ctx, tpdf->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100283 FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free);
284
285 lysp_type_free(ctx, &tpdf->type);
286
287}
288
Michal Vaskoc636ea42022-09-16 10:20:31 +0200289/**
290 * @brief Free the parsed grouping structure.
291 *
292 * @param[in] ctx Free context.
293 * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed.
294 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200295static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200296lysp_grp_free(struct lysf_ctx *ctx, struct lysp_node_grp *grp)
Radek Krejci19a96102018-11-15 13:38:09 +0100297{
298 struct lysp_node *node, *next;
299
Radek Krejci19a96102018-11-15 13:38:09 +0100300 FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100301 LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) {
302 lysp_node_free(ctx, node);
303 }
Radek Krejci01180ac2021-01-27 08:48:22 +0100304 LY_LIST_FOR_SAFE(grp->child, next, node) {
Radek Krejci19a96102018-11-15 13:38:09 +0100305 lysp_node_free(ctx, node);
306 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100307 LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) {
308 lysp_node_free(ctx, node);
309 }
310 LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) {
311 lysp_node_free(ctx, node);
312 }
Radek Krejci19a96102018-11-15 13:38:09 +0100313}
314
Radek Krejcif09e4e82019-06-14 15:08:11 +0200315void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200316lysp_when_free(struct lysf_ctx *ctx, struct lysp_when *when)
Radek Krejci19a96102018-11-15 13:38:09 +0100317{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200318 lydict_remove(ctx->ctx, when->cond);
319 lydict_remove(ctx->ctx, when->dsc);
320 lydict_remove(ctx->ctx, when->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100321 FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free);
322}
323
Michal Vaskoc636ea42022-09-16 10:20:31 +0200324/**
325 * @brief Free the parsed augment structure.
326 *
327 * @param[in] ctx Free context.
328 * @param[in] aug Parsed schema augment structure to free. Note that the structure itself is not freed.
329 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200330static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200331lysp_augment_free(struct lysf_ctx *ctx, struct lysp_node_augment *aug)
Radek Krejci19a96102018-11-15 13:38:09 +0100332{
333 struct lysp_node *node, *next;
334
Michal Vaskoc636ea42022-09-16 10:20:31 +0200335 LY_LIST_FOR_SAFE(aug->child, next, node) {
Radek Krejci19a96102018-11-15 13:38:09 +0100336 lysp_node_free(ctx, node);
337 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200338 LY_LIST_FOR_SAFE((struct lysp_node *)aug->actions, next, node) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100339 lysp_node_free(ctx, node);
340 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200341 LY_LIST_FOR_SAFE((struct lysp_node *)aug->notifs, next, node) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100342 lysp_node_free(ctx, node);
343 }
Radek Krejci19a96102018-11-15 13:38:09 +0100344}
345
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200346void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200347lysp_deviate_free(struct lysf_ctx *ctx, struct lysp_deviate *d)
Radek Krejci19a96102018-11-15 13:38:09 +0100348{
Michal Vasko22df3f02020-08-24 13:29:22 +0200349 struct lysp_deviate_add *add = (struct lysp_deviate_add *)d;
350 struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d;
Radek Krejci19a96102018-11-15 13:38:09 +0100351
Michal Vasko12ef5362022-09-16 15:13:58 +0200352 if (!d) {
353 return;
354 }
355
Radek Krejci19a96102018-11-15 13:38:09 +0100356 FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free);
Michal Vaskod989ba02020-08-24 10:59:24 +0200357 switch (d->mod) {
Radek Krejci19a96102018-11-15 13:38:09 +0100358 case LYS_DEV_NOT_SUPPORTED:
359 /* nothing to do */
360 break;
361 case LYS_DEV_ADD:
362 case LYS_DEV_DELETE: /* compatible for dynamically allocated data */
Michal Vaskoc636ea42022-09-16 10:20:31 +0200363 lydict_remove(ctx->ctx, add->units);
Radek Krejci19a96102018-11-15 13:38:09 +0100364 FREE_ARRAY(ctx, add->musts, lysp_restr_free);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200365 FREE_ARRAY(ctx->ctx, add->uniques, lysp_qname_free);
366 FREE_ARRAY(ctx->ctx, add->dflts, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100367 break;
368 case LYS_DEV_REPLACE:
369 FREE_MEMBER(ctx, rpl->type, lysp_type_free);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200370 lydict_remove(ctx->ctx, rpl->units);
371 lysp_qname_free(ctx->ctx, &rpl->dflt);
Radek Krejci19a96102018-11-15 13:38:09 +0100372 break;
373 default:
Michal Vaskoc636ea42022-09-16 10:20:31 +0200374 LOGINT(ctx->ctx);
Radek Krejci19a96102018-11-15 13:38:09 +0100375 break;
376 }
377}
378
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200379void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200380lysp_deviation_free(struct lysf_ctx *ctx, struct lysp_deviation *dev)
Radek Krejci19a96102018-11-15 13:38:09 +0100381{
382 struct lysp_deviate *next, *iter;
383
Michal Vaskoc636ea42022-09-16 10:20:31 +0200384 lydict_remove(ctx->ctx, dev->nodeid);
385 lydict_remove(ctx->ctx, dev->dsc);
386 lydict_remove(ctx->ctx, dev->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100387 LY_LIST_FOR_SAFE(dev->deviates, next, iter) {
388 lysp_deviate_free(ctx, iter);
389 free(iter);
390 }
391 FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free);
392}
393
Michal Vaskoc636ea42022-09-16 10:20:31 +0200394/**
395 * @brief Free the parsed refine structure.
396 *
397 * @param[in] ctx Free context.
398 * @param[in] ref Parsed schema refine structure to free. Note that the structure itself is not freed.
399 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200400static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200401lysp_refine_free(struct lysf_ctx *ctx, struct lysp_refine *ref)
Radek Krejci19a96102018-11-15 13:38:09 +0100402{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200403 lydict_remove(ctx->ctx, ref->nodeid);
404 lydict_remove(ctx->ctx, ref->dsc);
405 lydict_remove(ctx->ctx, ref->ref);
406 FREE_ARRAY(ctx->ctx, ref->iffeatures, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100407 FREE_ARRAY(ctx, ref->musts, lysp_restr_free);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200408 lydict_remove(ctx->ctx, ref->presence);
409 FREE_ARRAY(ctx->ctx, ref->dflts, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100410 FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free);
411}
412
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200413void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200414lysp_node_free(struct lysf_ctx *ctx, struct lysp_node *node)
Radek Krejci19a96102018-11-15 13:38:09 +0100415{
416 struct lysp_node *child, *next;
Michal Vasko856ea972021-06-09 09:44:30 +0200417 struct lysp_node_container *cont;
418 struct lysp_node_leaf *leaf;
419 struct lysp_node_leaflist *llist;
420 struct lysp_node_list *list;
421 struct lysp_node_choice *choice;
422 struct lysp_node_case *cas;
423 struct lysp_node_uses *uses;
424 struct lysp_node_action *act;
425 struct lysp_node_action_inout *inout;
426 struct lysp_node_notif *notif;
Radek Krejci9a3823e2021-01-27 20:26:46 +0100427 struct lysp_restr *musts = lysp_node_musts(node);
428 struct lysp_when *when = lysp_node_when(node);
Radek Krejci19a96102018-11-15 13:38:09 +0100429
Michal Vaskoc636ea42022-09-16 10:20:31 +0200430 lydict_remove(ctx->ctx, node->name);
431 lydict_remove(ctx->ctx, node->dsc);
432 lydict_remove(ctx->ctx, node->ref);
433 FREE_ARRAY(ctx->ctx, node->iffeatures, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100434 FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free);
435
Radek Krejci9a3823e2021-01-27 20:26:46 +0100436 FREE_MEMBER(ctx, when, lysp_when_free);
437 FREE_ARRAY(ctx, musts, lysp_restr_free);
438
Michal Vaskod989ba02020-08-24 10:59:24 +0200439 switch (node->nodetype) {
Radek Krejci19a96102018-11-15 13:38:09 +0100440 case LYS_CONTAINER:
Michal Vasko856ea972021-06-09 09:44:30 +0200441 cont = (struct lysp_node_container *)node;
442
Michal Vaskoc636ea42022-09-16 10:20:31 +0200443 lydict_remove(ctx->ctx, cont->presence);
Michal Vasko856ea972021-06-09 09:44:30 +0200444 FREE_ARRAY(ctx, cont->typedefs, lysp_tpdf_free);
445 if (cont->groupings) {
446 LY_LIST_FOR_SAFE(&cont->groupings->node, next, child) {
447 lysp_node_free(ctx, child);
448 }
449 }
450 LY_LIST_FOR_SAFE(cont->child, next, child) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100451 lysp_node_free(ctx, child);
452 }
Michal Vasko856ea972021-06-09 09:44:30 +0200453 if (cont->actions) {
454 LY_LIST_FOR_SAFE(&cont->actions->node, next, child) {
455 lysp_node_free(ctx, child);
456 }
Radek Krejci19a96102018-11-15 13:38:09 +0100457 }
Michal Vasko856ea972021-06-09 09:44:30 +0200458 if (cont->notifs) {
459 LY_LIST_FOR_SAFE(&cont->notifs->node, next, child) {
460 lysp_node_free(ctx, child);
461 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100462 }
Radek Krejci19a96102018-11-15 13:38:09 +0100463 break;
464 case LYS_LEAF:
Michal Vasko856ea972021-06-09 09:44:30 +0200465 leaf = (struct lysp_node_leaf *)node;
466
467 lysp_type_free(ctx, &leaf->type);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200468 lydict_remove(ctx->ctx, leaf->units);
469 lydict_remove(ctx->ctx, leaf->dflt.str);
Radek Krejci19a96102018-11-15 13:38:09 +0100470 break;
471 case LYS_LEAFLIST:
Michal Vasko856ea972021-06-09 09:44:30 +0200472 llist = (struct lysp_node_leaflist *)node;
473
474 lysp_type_free(ctx, &llist->type);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200475 lydict_remove(ctx->ctx, llist->units);
476 FREE_ARRAY(ctx->ctx, llist->dflts, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100477 break;
478 case LYS_LIST:
Michal Vasko856ea972021-06-09 09:44:30 +0200479 list = (struct lysp_node_list *)node;
480
Michal Vaskoc636ea42022-09-16 10:20:31 +0200481 lydict_remove(ctx->ctx, list->key);
Michal Vasko856ea972021-06-09 09:44:30 +0200482 FREE_ARRAY(ctx, list->typedefs, lysp_tpdf_free);
483 if (list->groupings) {
484 LY_LIST_FOR_SAFE(&list->groupings->node, next, child) {
485 lysp_node_free(ctx, child);
486 }
487 }
488 LY_LIST_FOR_SAFE(list->child, next, child) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100489 lysp_node_free(ctx, child);
490 }
Michal Vasko856ea972021-06-09 09:44:30 +0200491 if (list->actions) {
492 LY_LIST_FOR_SAFE(&list->actions->node, next, child) {
493 lysp_node_free(ctx, child);
494 }
Radek Krejci19a96102018-11-15 13:38:09 +0100495 }
Michal Vasko856ea972021-06-09 09:44:30 +0200496 if (list->notifs) {
497 LY_LIST_FOR_SAFE(&list->notifs->node, next, child) {
498 lysp_node_free(ctx, child);
499 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100500 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200501 FREE_ARRAY(ctx->ctx, list->uniques, lysp_qname_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100502 break;
503 case LYS_CHOICE:
Michal Vasko856ea972021-06-09 09:44:30 +0200504 choice = (struct lysp_node_choice *)node;
505
506 LY_LIST_FOR_SAFE(choice->child, next, child) {
Radek Krejci19a96102018-11-15 13:38:09 +0100507 lysp_node_free(ctx, child);
508 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200509 lydict_remove(ctx->ctx, choice->dflt.str);
Radek Krejci19a96102018-11-15 13:38:09 +0100510 break;
511 case LYS_CASE:
Michal Vasko856ea972021-06-09 09:44:30 +0200512 cas = (struct lysp_node_case *)node;
513
514 LY_LIST_FOR_SAFE(cas->child, next, child) {
Radek Krejci19a96102018-11-15 13:38:09 +0100515 lysp_node_free(ctx, child);
516 }
517 break;
518 case LYS_ANYDATA:
519 case LYS_ANYXML:
Radek Krejci9a3823e2021-01-27 20:26:46 +0100520 /* nothing special to do */
Radek Krejci19a96102018-11-15 13:38:09 +0100521 break;
522 case LYS_USES:
Michal Vasko856ea972021-06-09 09:44:30 +0200523 uses = (struct lysp_node_uses *)node;
524
525 FREE_ARRAY(ctx, uses->refines, lysp_refine_free);
526 if (uses->augments) {
527 LY_LIST_FOR_SAFE(&uses->augments->node, next, child) {
528 lysp_node_free(ctx, child);
529 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100530 }
531 break;
532 case LYS_RPC:
533 case LYS_ACTION:
Michal Vasko856ea972021-06-09 09:44:30 +0200534 act = (struct lysp_node_action *)node;
535
536 FREE_ARRAY(ctx, act->typedefs, lysp_tpdf_free);
537 if (act->groupings) {
538 LY_LIST_FOR_SAFE(&act->groupings->node, next, child) {
539 lysp_node_free(ctx, child);
540 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100541 }
Michal Vasko856ea972021-06-09 09:44:30 +0200542 if (act->input.nodetype) {
543 lysp_node_free(ctx, &act->input.node);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100544 }
Michal Vasko856ea972021-06-09 09:44:30 +0200545 if (act->output.nodetype) {
546 lysp_node_free(ctx, &act->output.node);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100547 }
548 break;
549 case LYS_INPUT:
550 case LYS_OUTPUT:
Michal Vasko856ea972021-06-09 09:44:30 +0200551 inout = (struct lysp_node_action_inout *)node;
552
553 FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free);
554 if (inout->groupings) {
555 LY_LIST_FOR_SAFE(&inout->groupings->node, next, child) {
556 lysp_node_free(ctx, child);
557 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100558 }
Michal Vasko856ea972021-06-09 09:44:30 +0200559 LY_LIST_FOR_SAFE(inout->child, next, child) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100560 lysp_node_free(ctx, child);
561 }
562 /* do not free the node, it is never standalone but part of the action node */
563 return;
564 case LYS_NOTIF:
Michal Vasko856ea972021-06-09 09:44:30 +0200565 notif = (struct lysp_node_notif *)node;
566
567 FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free);
568 if (notif->groupings) {
569 LY_LIST_FOR_SAFE(&notif->groupings->node, next, child) {
570 lysp_node_free(ctx, child);
571 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100572 }
Michal Vasko856ea972021-06-09 09:44:30 +0200573 LY_LIST_FOR_SAFE(notif->child, next, child) {
Radek Krejci2a9fc652021-01-22 17:44:34 +0100574 lysp_node_free(ctx, child);
575 }
576 break;
577 case LYS_GROUPING:
578 lysp_grp_free(ctx, (struct lysp_node_grp *)node);
579 break;
580 case LYS_AUGMENT:
Radek Krejci9a3823e2021-01-27 20:26:46 +0100581 lysp_augment_free(ctx, ((struct lysp_node_augment *)node));
Radek Krejci19a96102018-11-15 13:38:09 +0100582 break;
583 default:
Michal Vaskoc636ea42022-09-16 10:20:31 +0200584 LOGINT(ctx->ctx);
Radek Krejci19a96102018-11-15 13:38:09 +0100585 }
586
587 free(node);
588}
589
Radek Krejci15f10ab2020-11-03 14:14:14 +0100590void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200591lysp_module_free(struct lysf_ctx *ctx, struct lysp_module *module)
Radek Krejci19a96102018-11-15 13:38:09 +0100592{
Radek Krejci19a96102018-11-15 13:38:09 +0100593 struct lysp_node *node, *next;
594
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100595 if (!module) {
596 return;
597 }
Radek Krejci19a96102018-11-15 13:38:09 +0100598
599 FREE_ARRAY(ctx, module->imports, lysp_import_free);
Radek Krejci771928a2021-01-19 13:42:36 +0100600 FREE_ARRAY(ctx, module->includes, module->is_submod ? lysp_include_free_submodule : lysp_include_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100601
Radek Krejci19a96102018-11-15 13:38:09 +0100602 FREE_ARRAY(ctx, module->revs, lysp_revision_free);
603 FREE_ARRAY(ctx, module->extensions, lysp_ext_free);
604 FREE_ARRAY(ctx, module->features, lysp_feature_free);
605 FREE_ARRAY(ctx, module->identities, lysp_ident_free);
606 FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100607 LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) {
608 lysp_node_free(ctx, node);
609 }
Radek Krejci19a96102018-11-15 13:38:09 +0100610 LY_LIST_FOR_SAFE(module->data, next, node) {
611 lysp_node_free(ctx, node);
612 }
Radek Krejci2a9fc652021-01-22 17:44:34 +0100613 LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) {
614 lysp_node_free(ctx, node);
615 }
616 LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) {
617 lysp_node_free(ctx, node);
618 }
619 LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) {
620 lysp_node_free(ctx, node);
621 }
Radek Krejci19a96102018-11-15 13:38:09 +0100622 FREE_ARRAY(ctx, module->deviations, lysp_deviation_free);
623 FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free);
624
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200625 if (module->is_submod) {
626 struct lysp_submodule *submod = (struct lysp_submodule *)module;
627
Michal Vaskoc636ea42022-09-16 10:20:31 +0200628 lydict_remove(ctx->ctx, submod->name);
629 lydict_remove(ctx->ctx, submod->filepath);
630 lydict_remove(ctx->ctx, submod->prefix);
631 lydict_remove(ctx->ctx, submod->org);
632 lydict_remove(ctx->ctx, submod->contact);
633 lydict_remove(ctx->ctx, submod->dsc);
634 lydict_remove(ctx->ctx, submod->ref);
Michal Vasko5d24f6c2020-10-13 13:49:06 +0200635 }
636
Radek Krejci19a96102018-11-15 13:38:09 +0100637 free(module);
638}
639
Michal Vaskoc636ea42022-09-16 10:20:31 +0200640/**
641 * @brief Free the compiled extension definition and NULL the provided pointer.
642 *
643 * @param[in] ctx Free context.
644 * @param[in,out] ext Compiled extension definition to be freed.
645 */
646static void
647lysc_extension_free(struct lysf_ctx *ctx, struct lysc_ext **ext)
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100648{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200649 if (ly_set_contains(&ctx->ext_set, *ext, NULL)) {
650 /* already freed and only referenced again in this module */
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100651 return;
652 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200653
Michal Vasko6224d942022-09-19 12:32:47 +0200654 /* remember this extension to be freed, nothing to do on error */
655 (void)ly_set_add(&ctx->ext_set, *ext, 0, NULL);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200656
657 /* recursive exts free */
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100658 FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200659
Radek Krejci720d2612021-03-03 19:44:22 +0100660 *ext = NULL;
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100661}
662
663void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200664lysc_ext_instance_free(struct lysf_ctx *ctx, struct lysc_ext_instance *ext)
Radek Krejci19a96102018-11-15 13:38:09 +0100665{
fredganebc50572019-10-31 15:39:23 +0800666 if (ext->def && ext->def->plugin && ext->def->plugin->free) {
Michal Vaskoc636ea42022-09-16 10:20:31 +0200667 ext->def->plugin->free(ctx->ctx, ext);
Radek Krejci38d85362019-09-05 16:26:38 +0200668 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200669 lydict_remove(ctx->ctx, ext->argument);
Radek Krejci0935f412019-08-20 16:15:18 +0200670 FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free);
671}
672
673void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200674lysc_iffeature_free(struct lysf_ctx *UNUSED(ctx), struct lysc_iffeature *iff)
Radek Krejci19a96102018-11-15 13:38:09 +0100675{
676 LY_ARRAY_FREE(iff->features);
677 free(iff->expr);
678}
679
Michal Vaskoc636ea42022-09-16 10:20:31 +0200680/**
681 * @brief Free the compiled when structure (decrease refcount) and NULL the provided pointer.
682 *
683 * @param[in] ctx Free context.
684 * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed.
685 */
Radek Krejci19a96102018-11-15 13:38:09 +0100686static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200687lysc_when_free(struct lysf_ctx *ctx, struct lysc_when **w)
Radek Krejci58d171e2018-11-23 13:50:55 +0100688{
Radek Krejci00b874b2019-02-12 10:54:50 +0100689 if (--(*w)->refcount) {
690 return;
691 }
Michal Vaskoc636ea42022-09-16 10:20:31 +0200692 lyxp_expr_free(ctx->ctx, (*w)->cond);
Radek Krejci8df109d2021-04-23 12:19:08 +0200693 ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, (*w)->prefixes);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200694 lydict_remove(ctx->ctx, (*w)->dsc);
695 lydict_remove(ctx->ctx, (*w)->ref);
Radek Krejci00b874b2019-02-12 10:54:50 +0100696 FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free);
697 free(*w);
Radek Krejci58d171e2018-11-23 13:50:55 +0100698}
699
Michal Vaskoc636ea42022-09-16 10:20:31 +0200700/**
701 * @brief Free the compiled must structure.
702 *
703 * @param[in] ctx Free context.
704 * @param[in,out] must Compiled must structure to be freed.
705 * Since the structure is typically part of the sized array, the structure itself is not freed.
706 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200707static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200708lysc_must_free(struct lysf_ctx *ctx, struct lysc_must *must)
Radek Krejci58d171e2018-11-23 13:50:55 +0100709{
Michal Vaskoedb0fa52022-10-04 10:36:00 +0200710 if (!must) {
711 return;
712 }
713
Michal Vaskoc636ea42022-09-16 10:20:31 +0200714 lyxp_expr_free(ctx->ctx, must->cond);
Radek Krejci8df109d2021-04-23 12:19:08 +0200715 ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, must->prefixes);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200716 lydict_remove(ctx->ctx, must->emsg);
717 lydict_remove(ctx->ctx, must->eapptag);
718 lydict_remove(ctx->ctx, must->dsc);
719 lydict_remove(ctx->ctx, must->ref);
Radek Krejci58d171e2018-11-23 13:50:55 +0100720 FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free);
721}
722
Michal Vaskoc636ea42022-09-16 10:20:31 +0200723/**
724 * @brief Unlink the identity from all derived identity arrays.
725 *
726 * @param[in] ident Identity to unlink.
727 */
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100728static void
729lysc_ident_derived_unlink(const struct lysc_ident *ident)
730{
731 LY_ARRAY_COUNT_TYPE u, v, w;
732 const struct lysp_submodule *submod;
Michal Vaskod84b8132022-03-15 10:45:44 +0100733 const struct lysp_module *base_pmod = NULL;
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100734 const struct lysp_ident *identp = NULL;
Michal Vaskod6b5d4e2022-03-16 09:23:32 +0100735 const struct lys_module *mod, *iter;
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100736 const char *base_name;
Michal Vaskod6b5d4e2022-03-16 09:23:32 +0100737 uint32_t i;
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100738
739 /* find the parsed identity */
740 LY_ARRAY_FOR(ident->module->parsed->identities, u) {
741 if (ident->module->parsed->identities[u].name == ident->name) {
742 identp = &ident->module->parsed->identities[u];
743 base_pmod = ident->module->parsed;
744 break;
745 }
746 }
747 if (!identp) {
748 LY_ARRAY_FOR(ident->module->parsed->includes, v) {
749 submod = ident->module->parsed->includes[v].submodule;
750 LY_ARRAY_FOR(submod->identities, u) {
751 if (submod->identities[u].name == ident->name) {
752 identp = &submod->identities[u];
753 base_pmod = (struct lysp_module *)submod;
754 break;
755 }
756 }
757 }
758 }
759 assert(identp);
760
761 /* remove link from all the foreign bases, it may not be there if identity compilation failed */
762 LY_ARRAY_FOR(identp->bases, u) {
763 base_name = strchr(identp->bases[u], ':');
764 if (!base_name) {
765 continue;
766 }
767
768 /* prefixed identity */
769 mod = ly_resolve_prefix(ident->module->ctx, identp->bases[u], base_name - identp->bases[u], LY_VALUE_SCHEMA,
770 (void *)base_pmod);
771 if (!mod) {
772 continue;
773 }
774 ++base_name;
775
Michal Vaskod6b5d4e2022-03-16 09:23:32 +0100776 i = 0;
777 while ((iter = ly_ctx_get_module_iter(ident->module->ctx, &i))) {
778 if (iter == mod) {
779 break;
780 }
781 }
782 if (!iter) {
783 /* target module was freed already */
784 continue;
785 }
786
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100787 /* find the compiled base */
788 LY_ARRAY_FOR(mod->identities, v) {
789 if (!strcmp(mod->identities[v].name, base_name)) {
790 /* find the derived link */
791 LY_ARRAY_FOR(mod->identities[v].derived, w) {
792 if (mod->identities[v].derived[w] == ident) {
793 /* remove the link */
794 LY_ARRAY_DECREMENT(mod->identities[v].derived);
Michal Vasko3fedda12022-03-16 09:23:45 +0100795 if (!LY_ARRAY_COUNT(mod->identities[v].derived)) {
796 LY_ARRAY_FREE(mod->identities[v].derived);
797 mod->identities[v].derived = NULL;
798 } else if (w < LY_ARRAY_COUNT(mod->identities[v].derived)) {
Michal Vasko4f9da5e2022-03-14 13:11:26 +0100799 memmove(mod->identities[v].derived + w, mod->identities[v].derived + w + 1,
800 (LY_ARRAY_COUNT(mod->identities[v].derived) - w) * sizeof ident);
801 }
802 break;
803 }
804 }
805 break;
806 }
807 }
808 }
809}
810
Michal Vaskoc636ea42022-09-16 10:20:31 +0200811/**
812 * @brief Free the compiled identity structure.
813 *
814 * @param[in] ctx Free context.
815 * @param[in,out] ident Compiled identity structure to be freed.
816 * Since the structure is typically part of the sized array, the structure itself is not freed.
817 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200818static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200819lysc_ident_free(struct lysf_ctx *ctx, struct lysc_ident *ident)
Radek Krejci19a96102018-11-15 13:38:09 +0100820{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200821 lydict_remove(ctx->ctx, ident->name);
822 lydict_remove(ctx->ctx, ident->dsc);
823 lydict_remove(ctx->ctx, ident->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100824 LY_ARRAY_FREE(ident->derived);
825 FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free);
826}
827
Michal Vaskoc636ea42022-09-16 10:20:31 +0200828/**
829 * @brief Free the compiled range structure.
830 *
831 * @param[in] ctx Free context.
832 * @param[in,out] range Compiled range structure to be freed.
833 * Since the structure is typically part of the sized array, the structure itself is not freed.
834 */
Radek Krejci19a96102018-11-15 13:38:09 +0100835static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200836lysc_range_free(struct lysf_ctx *ctx, struct lysc_range *range)
Radek Krejci19a96102018-11-15 13:38:09 +0100837{
838 LY_ARRAY_FREE(range->parts);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200839 lydict_remove(ctx->ctx, range->eapptag);
840 lydict_remove(ctx->ctx, range->emsg);
841 lydict_remove(ctx->ctx, range->dsc);
842 lydict_remove(ctx->ctx, range->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100843 FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free);
844}
845
Michal Vasko51de7b72022-04-29 09:50:22 +0200846void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200847lysc_pattern_free(struct lysf_ctx *ctx, struct lysc_pattern **pattern)
Radek Krejci19a96102018-11-15 13:38:09 +0100848{
849 if (--(*pattern)->refcount) {
850 return;
851 }
Radek Krejci54579462019-04-30 12:47:06 +0200852 pcre2_code_free((*pattern)->code);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200853 lydict_remove(ctx->ctx, (*pattern)->expr);
854 lydict_remove(ctx->ctx, (*pattern)->eapptag);
855 lydict_remove(ctx->ctx, (*pattern)->emsg);
856 lydict_remove(ctx->ctx, (*pattern)->dsc);
857 lydict_remove(ctx->ctx, (*pattern)->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100858 FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free);
859 free(*pattern);
860}
861
Michal Vaskof4fa90d2021-11-11 15:05:19 +0100862void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200863lysc_enum_item_free(struct lysf_ctx *ctx, struct lysc_type_bitenum_item *item)
Radek Krejci19a96102018-11-15 13:38:09 +0100864{
Michal Vaskoc636ea42022-09-16 10:20:31 +0200865 lydict_remove(ctx->ctx, item->name);
866 lydict_remove(ctx->ctx, item->dsc);
867 lydict_remove(ctx->ctx, item->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100868 FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free);
869}
870
Michal Vaskoc636ea42022-09-16 10:20:31 +0200871/**
872 * @brief Free the compiled type structure.
873 *
874 * @param[in] ctx Free context.
875 * @param[in,out] type Pointer to compiled type structure to be freed.
876 * Since the structure is typically part of the sized array, the structure itself is not freed.
877 */
Radek Krejcia3045382018-11-22 14:30:31 +0100878static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200879lysc_type2_free(struct lysf_ctx *ctx, struct lysc_type **type)
Radek Krejcia3045382018-11-22 14:30:31 +0100880{
881 lysc_type_free(ctx, *type);
882}
Radek Krejci0f969882020-08-21 16:56:47 +0200883
Radek Krejcicdfecd92018-11-26 11:27:32 +0100884void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200885lysc_type_free(struct lysf_ctx *ctx, struct lysc_type *type)
Radek Krejci19a96102018-11-15 13:38:09 +0100886{
Michal Vaskod15c7de2022-05-09 15:34:09 +0200887 if (!type || (LY_ATOMIC_DEC_BARRIER(type->refcount) > 1)) {
Radek Krejci19a96102018-11-15 13:38:09 +0100888 return;
889 }
Radek Krejcib915ac92020-08-14 23:31:04 +0200890
Michal Vaskod989ba02020-08-24 10:59:24 +0200891 switch (type->basetype) {
Radek Krejci19a96102018-11-15 13:38:09 +0100892 case LY_TYPE_BINARY:
Michal Vasko22df3f02020-08-24 13:29:22 +0200893 FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100894 break;
895 case LY_TYPE_BITS:
Michal Vasko22df3f02020-08-24 13:29:22 +0200896 FREE_ARRAY(ctx, (struct lysc_type_bitenum_item *)((struct lysc_type_bits *)type)->bits, lysc_enum_item_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100897 break;
Radek Krejci6cba4292018-11-15 17:33:29 +0100898 case LY_TYPE_DEC64:
Michal Vasko22df3f02020-08-24 13:29:22 +0200899 FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free);
Radek Krejci6cba4292018-11-15 17:33:29 +0100900 break;
Radek Krejci19a96102018-11-15 13:38:09 +0100901 case LY_TYPE_STRING:
Michal Vasko22df3f02020-08-24 13:29:22 +0200902 FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free);
903 FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100904 break;
905 case LY_TYPE_ENUM:
Michal Vasko22df3f02020-08-24 13:29:22 +0200906 FREE_ARRAY(ctx, ((struct lysc_type_enum *)type)->enums, lysc_enum_item_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100907 break;
908 case LY_TYPE_INT8:
909 case LY_TYPE_UINT8:
910 case LY_TYPE_INT16:
911 case LY_TYPE_UINT16:
912 case LY_TYPE_INT32:
913 case LY_TYPE_UINT32:
914 case LY_TYPE_INT64:
915 case LY_TYPE_UINT64:
Michal Vasko22df3f02020-08-24 13:29:22 +0200916 FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100917 break;
Radek Krejci555cb5b2018-11-16 14:54:33 +0100918 case LY_TYPE_IDENT:
Michal Vasko22df3f02020-08-24 13:29:22 +0200919 LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases);
Radek Krejci555cb5b2018-11-16 14:54:33 +0100920 break;
Radek Krejcia3045382018-11-22 14:30:31 +0100921 case LY_TYPE_UNION:
Michal Vasko22df3f02020-08-24 13:29:22 +0200922 FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free);
Radek Krejcia3045382018-11-22 14:30:31 +0100923 break;
924 case LY_TYPE_LEAFREF:
Michal Vaskoc636ea42022-09-16 10:20:31 +0200925 lyxp_expr_free(ctx->ctx, ((struct lysc_type_leafref *)type)->path);
Radek Krejci8df109d2021-04-23 12:19:08 +0200926 ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes);
Michal Vaskod15c7de2022-05-09 15:34:09 +0200927 lysc_type_free(ctx, ((struct lysc_type_leafref *)type)->realtype);
Radek Krejcia3045382018-11-22 14:30:31 +0100928 break;
Radek Krejci16c0f822018-11-16 10:46:10 +0100929 case LY_TYPE_INST:
Radek Krejci19a96102018-11-15 13:38:09 +0100930 case LY_TYPE_BOOL:
931 case LY_TYPE_EMPTY:
Radek Krejci43699232018-11-23 14:59:46 +0100932 case LY_TYPE_UNKNOWN:
Radek Krejci19a96102018-11-15 13:38:09 +0100933 /* nothing to do */
934 break;
935 }
Michal Vaskoba99a3e2020-08-18 15:50:05 +0200936
937 FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100938 free(type);
939}
940
Michal Vaskoc636ea42022-09-16 10:20:31 +0200941/**
942 * @brief Free the compiled input/output structure.
943 *
944 * @param[in] ctx Free context.
945 * @param[in,out] inout Compiled inout structure to be freed.
946 * Since the structure is part of the RPC/action structure, it is not freed itself.
947 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200948static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200949lysc_node_action_inout_free(struct lysf_ctx *ctx, struct lysc_node_action_inout *inout)
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100950{
951 struct lysc_node *child, *child_next;
952
Radek Krejcif538ce52019-03-05 10:46:14 +0100953 FREE_ARRAY(ctx, inout->musts, lysc_must_free);
Radek Krejci01180ac2021-01-27 08:48:22 +0100954 LY_LIST_FOR_SAFE(inout->child, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100955 lysc_node_free_(ctx, child);
Radek Krejcif538ce52019-03-05 10:46:14 +0100956 }
957}
958
Michal Vaskoc636ea42022-09-16 10:20:31 +0200959/**
960 * @brief Free the compiled RPC/action structure.
961 *
962 * @param[in] ctx Free context.
963 * @param[in,out] action Compiled RPC/action structure to be freed.
964 * Since the structure is typically part of the sized array, the structure itself is not freed.
965 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200966static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200967lysc_node_action_free(struct lysf_ctx *ctx, struct lysc_node_action *action)
Radek Krejcif538ce52019-03-05 10:46:14 +0100968{
Michal Vasko37a0fe62021-02-03 09:53:04 +0100969 FREE_ARRAY(ctx, action->when, lysc_when_free);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100970 if (action->input.nodetype) {
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100971 lysc_node_free_(ctx, &action->input.node);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100972 }
973 if (action->output.nodetype) {
Michal Vasko14ed9cd2021-01-28 14:16:25 +0100974 lysc_node_free_(ctx, &action->output.node);
Radek Krejci2a9fc652021-01-22 17:44:34 +0100975 }
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100976}
977
Michal Vaskoc636ea42022-09-16 10:20:31 +0200978/**
979 * @brief Free the compiled notification structure.
980 *
981 * @param[in] ctx Free context.
982 * @param[in,out] notif Compiled notification structure to be freed.
983 * Since the structure is typically part of the sized array, the structure itself is not freed.
984 */
Michal Vasko12ef5362022-09-16 15:13:58 +0200985static void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200986lysc_node_notif_free(struct lysf_ctx *ctx, struct lysc_node_notif *notif)
Radek Krejcifc11bd72019-04-11 16:00:05 +0200987{
988 struct lysc_node *child, *child_next;
989
Michal Vasko37a0fe62021-02-03 09:53:04 +0100990 FREE_ARRAY(ctx, notif->when, lysc_when_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200991 FREE_ARRAY(ctx, notif->musts, lysc_must_free);
Radek Krejci01180ac2021-01-27 08:48:22 +0100992 LY_LIST_FOR_SAFE(notif->child, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +0100993 lysc_node_free_(ctx, child);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200994 }
995}
996
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200997void
Michal Vaskoc636ea42022-09-16 10:20:31 +0200998lysc_node_container_free(struct lysf_ctx *ctx, struct lysc_node_container *node)
Radek Krejci19a96102018-11-15 13:38:09 +0100999{
1000 struct lysc_node *child, *child_next;
1001
1002 LY_LIST_FOR_SAFE(node->child, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001003 lysc_node_free_(ctx, child);
Radek Krejci19a96102018-11-15 13:38:09 +01001004 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001005 LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) {
1006 lysc_node_free_(ctx, child);
1007 }
1008 LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) {
1009 lysc_node_free_(ctx, child);
1010 }
Radek Krejci9a3823e2021-01-27 20:26:46 +01001011 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci58d171e2018-11-23 13:50:55 +01001012 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci19a96102018-11-15 13:38:09 +01001013}
1014
Michal Vaskoc636ea42022-09-16 10:20:31 +02001015/**
1016 * @brief Free the compiled leaf structure.
1017 *
1018 * @param[in] ctx Free context.
1019 * @param[in,out] node Compiled leaf structure to be freed.
1020 * Since the structure is typically part of the sized array, the structure itself is not freed.
1021 */
Radek Krejci19a96102018-11-15 13:38:09 +01001022static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001023lysc_node_leaf_free(struct lysf_ctx *ctx, struct lysc_node_leaf *node)
Radek Krejci19a96102018-11-15 13:38:09 +01001024{
Radek Krejci9a3823e2021-01-27 20:26:46 +01001025 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci58d171e2018-11-23 13:50:55 +01001026 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci19a96102018-11-15 13:38:09 +01001027 if (node->type) {
1028 lysc_type_free(ctx, node->type);
1029 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001030 lydict_remove(ctx->ctx, node->units);
Radek Krejcia1911222019-07-22 17:24:50 +02001031 if (node->dflt) {
Michal Vaskoc636ea42022-09-16 10:20:31 +02001032 node->dflt->realtype->plugin->free(ctx->ctx, node->dflt);
Michal Vaskofeca4fb2020-10-05 08:58:40 +02001033 lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype);
Radek Krejcia1911222019-07-22 17:24:50 +02001034 free(node->dflt);
1035 }
Radek Krejci19a96102018-11-15 13:38:09 +01001036}
1037
Michal Vaskoc636ea42022-09-16 10:20:31 +02001038/**
1039 * @brief Free the compiled leaflist structure.
1040 *
1041 * @param[in] ctx Free context.
1042 * @param[in,out] node Compiled leaflist structure to be freed.
1043 * Since the structure is typically part of the sized array, the structure itself is not freed.
1044 */
Radek Krejci42452ac2018-11-28 17:09:52 +01001045static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001046lysc_node_leaflist_free(struct lysf_ctx *ctx, struct lysc_node_leaflist *node)
Radek Krejci42452ac2018-11-28 17:09:52 +01001047{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001048 LY_ARRAY_COUNT_TYPE u;
Radek Krejci42452ac2018-11-28 17:09:52 +01001049
Radek Krejci9a3823e2021-01-27 20:26:46 +01001050 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci42452ac2018-11-28 17:09:52 +01001051 FREE_ARRAY(ctx, node->musts, lysc_must_free);
1052 if (node->type) {
1053 lysc_type_free(ctx, node->type);
1054 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001055 lydict_remove(ctx->ctx, node->units);
Radek Krejci42452ac2018-11-28 17:09:52 +01001056 LY_ARRAY_FOR(node->dflts, u) {
Michal Vaskoc636ea42022-09-16 10:20:31 +02001057 node->dflts[u]->realtype->plugin->free(ctx->ctx, node->dflts[u]);
Michal Vaskofeca4fb2020-10-05 08:58:40 +02001058 lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype);
Radek Krejcia1911222019-07-22 17:24:50 +02001059 free(node->dflts[u]);
Radek Krejci42452ac2018-11-28 17:09:52 +01001060 }
1061 LY_ARRAY_FREE(node->dflts);
1062}
1063
Michal Vaskoc636ea42022-09-16 10:20:31 +02001064/**
1065 * @brief Free the compiled list structure.
1066 *
1067 * @param[in] ctx Free context.
1068 * @param[in,out] node Compiled list structure to be freed.
1069 * Since the structure is typically part of the sized array, the structure itself is not freed.
1070 */
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001071static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001072lysc_node_list_free(struct lysf_ctx *ctx, struct lysc_node_list *node)
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001073{
Michal Vaskofd69e1d2020-07-03 11:57:17 +02001074 LY_ARRAY_COUNT_TYPE u;
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001075 struct lysc_node *child, *child_next;
1076
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001077 LY_LIST_FOR_SAFE(node->child, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001078 lysc_node_free_(ctx, child);
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001079 }
Radek Krejci9a3823e2021-01-27 20:26:46 +01001080 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001081 FREE_ARRAY(ctx, node->musts, lysc_must_free);
1082
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001083 LY_ARRAY_FOR(node->uniques, u) {
1084 LY_ARRAY_FREE(node->uniques[u]);
1085 }
1086 LY_ARRAY_FREE(node->uniques);
1087
Radek Krejci2a9fc652021-01-22 17:44:34 +01001088 LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) {
1089 lysc_node_free_(ctx, child);
1090 }
1091 LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) {
1092 lysc_node_free_(ctx, child);
1093 }
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001094}
1095
Michal Vaskoc636ea42022-09-16 10:20:31 +02001096/**
1097 * @brief Free the compiled choice structure.
1098 *
1099 * @param[in] ctx Free context.
1100 * @param[in,out] node Compiled choice structure to be freed.
1101 * Since the structure is typically part of the sized array, the structure itself is not freed.
1102 */
Radek Krejci056d0a82018-12-06 16:57:25 +01001103static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001104lysc_node_choice_free(struct lysf_ctx *ctx, struct lysc_node_choice *node)
Radek Krejci056d0a82018-12-06 16:57:25 +01001105{
1106 struct lysc_node *child, *child_next;
1107
Radek Krejci9a3823e2021-01-27 20:26:46 +01001108 FREE_ARRAY(ctx, node->when, lysc_when_free);
Michal Vasko20424b42020-08-31 12:29:38 +02001109 LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001110 lysc_node_free_(ctx, child);
Michal Vasko20424b42020-08-31 12:29:38 +02001111 }
1112}
1113
Michal Vaskoc636ea42022-09-16 10:20:31 +02001114/**
1115 * @brief Free the compiled case structure.
1116 *
1117 * @param[in] ctx Free context.
1118 * @param[in,out] node Compiled case structure to be freed.
1119 * Since the structure is typically part of the sized array, the structure itself is not freed.
1120 */
Michal Vasko20424b42020-08-31 12:29:38 +02001121static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001122lysc_node_case_free(struct lysf_ctx *ctx, struct lysc_node_case *node)
Michal Vasko20424b42020-08-31 12:29:38 +02001123{
1124 struct lysc_node *child, *child_next;
1125
Radek Krejci9a3823e2021-01-27 20:26:46 +01001126 FREE_ARRAY(ctx, node->when, lysc_when_free);
Michal Vasko20424b42020-08-31 12:29:38 +02001127 LY_LIST_FOR_SAFE(node->child, child_next, child) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001128 lysc_node_free_(ctx, child);
Radek Krejci056d0a82018-12-06 16:57:25 +01001129 }
Radek Krejci9800fb82018-12-13 14:26:23 +01001130}
Radek Krejci056d0a82018-12-06 16:57:25 +01001131
Michal Vaskoc636ea42022-09-16 10:20:31 +02001132/**
1133 * @brief Free the compiled anyxml/anydata structure.
1134 *
1135 * @param[in] ctx Free context.
1136 * @param[in,out] node Compiled anyxml/anydata structure to be freed.
1137 * Since the structure is typically part of the sized array, the structure itself is not freed.
1138 */
Radek Krejci9800fb82018-12-13 14:26:23 +01001139static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001140lysc_node_anydata_free(struct lysf_ctx *ctx, struct lysc_node_anydata *node)
Radek Krejci9800fb82018-12-13 14:26:23 +01001141{
Radek Krejci9a3823e2021-01-27 20:26:46 +01001142 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci9800fb82018-12-13 14:26:23 +01001143 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci056d0a82018-12-06 16:57:25 +01001144}
1145
Michal Vaskoc636ea42022-09-16 10:20:31 +02001146/**
1147 * @brief Free the compiled node structure.
1148 *
1149 * @param[in] ctx Free context.
1150 * @param[in,out] node Compiled node structure to be freed.
1151 * Since the structure is typically part of the sized array, the structure itself is not freed.
1152 */
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001153static void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001154lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node)
Radek Krejci19a96102018-11-15 13:38:09 +01001155{
Radek Krejci2a9fc652021-01-22 17:44:34 +01001156 ly_bool inout = 0;
1157
Radek Krejci19a96102018-11-15 13:38:09 +01001158 /* common part */
Michal Vaskoc636ea42022-09-16 10:20:31 +02001159 lydict_remove(ctx->ctx, node->name);
1160 lydict_remove(ctx->ctx, node->dsc);
1161 lydict_remove(ctx->ctx, node->ref);
Radek Krejci19a96102018-11-15 13:38:09 +01001162
1163 /* nodetype-specific part */
Michal Vaskod989ba02020-08-24 10:59:24 +02001164 switch (node->nodetype) {
Radek Krejci19a96102018-11-15 13:38:09 +01001165 case LYS_CONTAINER:
Michal Vasko22df3f02020-08-24 13:29:22 +02001166 lysc_node_container_free(ctx, (struct lysc_node_container *)node);
Radek Krejci19a96102018-11-15 13:38:09 +01001167 break;
1168 case LYS_LEAF:
Michal Vasko22df3f02020-08-24 13:29:22 +02001169 lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node);
Radek Krejci19a96102018-11-15 13:38:09 +01001170 break;
Radek Krejci42452ac2018-11-28 17:09:52 +01001171 case LYS_LEAFLIST:
Michal Vasko22df3f02020-08-24 13:29:22 +02001172 lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node);
Radek Krejci42452ac2018-11-28 17:09:52 +01001173 break;
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001174 case LYS_LIST:
Michal Vasko22df3f02020-08-24 13:29:22 +02001175 lysc_node_list_free(ctx, (struct lysc_node_list *)node);
Radek Krejci9bb94eb2018-12-04 16:48:35 +01001176 break;
Radek Krejci056d0a82018-12-06 16:57:25 +01001177 case LYS_CHOICE:
Michal Vasko22df3f02020-08-24 13:29:22 +02001178 lysc_node_choice_free(ctx, (struct lysc_node_choice *)node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001179 break;
1180 case LYS_CASE:
Michal Vasko20424b42020-08-31 12:29:38 +02001181 lysc_node_case_free(ctx, (struct lysc_node_case *)node);
Radek Krejci056d0a82018-12-06 16:57:25 +01001182 break;
Radek Krejci9800fb82018-12-13 14:26:23 +01001183 case LYS_ANYDATA:
1184 case LYS_ANYXML:
Michal Vasko22df3f02020-08-24 13:29:22 +02001185 lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node);
Radek Krejci9800fb82018-12-13 14:26:23 +01001186 break;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001187 case LYS_RPC:
1188 case LYS_ACTION:
1189 lysc_node_action_free(ctx, (struct lysc_node_action *)node);
1190 break;
1191 case LYS_INPUT:
1192 case LYS_OUTPUT:
1193 lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node);
1194 inout = 1;
1195 break;
1196 case LYS_NOTIF:
1197 lysc_node_notif_free(ctx, (struct lysc_node_notif *)node);
1198 break;
Radek Krejci19a96102018-11-15 13:38:09 +01001199 default:
Michal Vaskoc636ea42022-09-16 10:20:31 +02001200 LOGINT(ctx->ctx);
Radek Krejci19a96102018-11-15 13:38:09 +01001201 }
1202
Radek Krejci056d0a82018-12-06 16:57:25 +01001203 FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001204
1205 if (!inout) {
1206 free(node);
1207 }
Radek Krejci19a96102018-11-15 13:38:09 +01001208}
1209
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001210void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001211lysc_node_free(struct lysf_ctx *ctx, struct lysc_node *node, ly_bool unlink)
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001212{
Michal Vaskoe02e7402021-07-23 08:29:28 +02001213 struct lysc_node *next, *iter, **child_p;
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001214
Radek Krejci2a9fc652021-01-22 17:44:34 +01001215 if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) {
Michal Vaskoe02e7402021-07-23 08:29:28 +02001216 /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */
1217 struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node;
Michal Vasko26bbb272022-08-02 14:54:33 +02001218
Michal Vaskoe02e7402021-07-23 08:29:28 +02001219 LY_LIST_FOR_SAFE(inout->child, next, iter) {
1220 lysc_node_free_(ctx, iter);
1221 }
1222 inout->child = NULL;
Radek Krejci2a9fc652021-01-22 17:44:34 +01001223 return;
1224 }
1225
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001226 if (unlink) {
1227 /* unlink from siblings */
1228 if (node->prev->next) {
1229 node->prev->next = node->next;
1230 }
1231 if (node->next) {
1232 node->next->prev = node->prev;
1233 } else {
1234 /* unlinking the last node */
1235 if (node->parent) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001236 if (node->nodetype == LYS_ACTION) {
1237 iter = (struct lysc_node *)lysc_node_actions(node->parent);
1238 } else if (node->nodetype == LYS_NOTIF) {
1239 iter = (struct lysc_node *)lysc_node_notifs(node->parent);
1240 } else {
Michal Vasko544e58a2021-01-28 14:33:41 +01001241 iter = (struct lysc_node *)lysc_node_child(node->parent);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001242 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001243 LY_CHECK_ERR_RET(!iter, LOGINT(ctx->ctx), );
Radek Krejci2a9fc652021-01-22 17:44:34 +01001244 } else if (node->nodetype == LYS_RPC) {
1245 iter = (struct lysc_node *)node->module->compiled->rpcs;
1246 } else if (node->nodetype == LYS_NOTIF) {
1247 iter = (struct lysc_node *)node->module->compiled->notifs;
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001248 } else {
1249 iter = node->module->compiled->data;
1250 }
1251 /* update the "last" pointer from the first node */
1252 iter->prev = node->prev;
1253 }
1254
1255 /* unlink from parent */
1256 if (node->parent) {
Radek Krejci2a9fc652021-01-22 17:44:34 +01001257 if (node->nodetype == LYS_ACTION) {
1258 child_p = (struct lysc_node **)lysc_node_actions_p(node->parent);
1259 } else if (node->nodetype == LYS_NOTIF) {
1260 child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent);
1261 } else {
Michal Vasko544e58a2021-01-28 14:33:41 +01001262 child_p = lysc_node_child_p(node->parent);
Radek Krejci2a9fc652021-01-22 17:44:34 +01001263 }
1264 } else if (node->nodetype == LYS_RPC) {
1265 child_p = (struct lysc_node **)&node->module->compiled->rpcs;
1266 } else if (node->nodetype == LYS_NOTIF) {
1267 child_p = (struct lysc_node **)&node->module->compiled->notifs;
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001268 } else {
1269 child_p = &node->module->compiled->data;
1270 }
1271 if (child_p && (*child_p == node)) {
1272 /* the node is the first child */
1273 *child_p = node->next;
1274 }
1275 }
1276
1277 lysc_node_free_(ctx, node);
1278}
1279
Radek Krejci90ed21e2021-04-12 14:47:46 +02001280void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001281lysc_module_free(struct lysf_ctx *ctx, struct lysc_module *module)
Radek Krejci19a96102018-11-15 13:38:09 +01001282{
Radek Krejci19a96102018-11-15 13:38:09 +01001283 struct lysc_node *node, *node_next;
1284
Radek Krejci90ed21e2021-04-12 14:47:46 +02001285 if (!module) {
1286 return;
1287 }
1288
Radek Krejci19a96102018-11-15 13:38:09 +01001289 LY_LIST_FOR_SAFE(module->data, node_next, node) {
Michal Vasko7b1ad1a2020-11-02 15:41:27 +01001290 lysc_node_free_(ctx, node);
Radek Krejci19a96102018-11-15 13:38:09 +01001291 }
Radek Krejci2a9fc652021-01-22 17:44:34 +01001292 LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) {
1293 lysc_node_free_(ctx, node);
1294 }
1295 LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) {
1296 lysc_node_free_(ctx, node);
1297 }
Radek Krejci19a96102018-11-15 13:38:09 +01001298 FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free);
1299
1300 free(module);
1301}
1302
1303void
Michal Vaskoc636ea42022-09-16 10:20:31 +02001304lys_module_free(struct lysf_ctx *ctx, struct lys_module *module, ly_bool remove_links)
Radek Krejci19a96102018-11-15 13:38:09 +01001305{
Michal Vasko4f9da5e2022-03-14 13:11:26 +01001306 LY_ARRAY_COUNT_TYPE u;
1307
Radek Krejci19a96102018-11-15 13:38:09 +01001308 if (!module) {
1309 return;
1310 }
Michal Vasko4f9da5e2022-03-14 13:11:26 +01001311
Michal Vaskoee757602021-06-10 14:38:19 +02001312 assert(!module->implemented);
1313 assert(!module->compiled);
Radek Krejci19a96102018-11-15 13:38:09 +01001314
Michal Vasko4f9da5e2022-03-14 13:11:26 +01001315 if (remove_links) {
1316 /* remove derived identity links */
1317 LY_ARRAY_FOR(module->identities, u) {
1318 lysc_ident_derived_unlink(&module->identities[u]);
1319 }
1320 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001321 FREE_ARRAY(ctx, module->identities, lysc_ident_free);
1322 lysp_module_free(ctx, module->parsed);
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001323
Michal Vasko7f45cf22020-10-01 12:49:44 +02001324 LY_ARRAY_FREE(module->augmented_by);
1325 LY_ARRAY_FREE(module->deviated_by);
1326
Michal Vaskoc636ea42022-09-16 10:20:31 +02001327 lydict_remove(ctx->ctx, module->name);
1328 lydict_remove(ctx->ctx, module->revision);
1329 lydict_remove(ctx->ctx, module->ns);
1330 lydict_remove(ctx->ctx, module->prefix);
1331 lydict_remove(ctx->ctx, module->filepath);
1332 lydict_remove(ctx->ctx, module->org);
1333 lydict_remove(ctx->ctx, module->contact);
1334 lydict_remove(ctx->ctx, module->dsc);
1335 lydict_remove(ctx->ctx, module->ref);
Radek Krejci0bcdaed2019-01-10 10:21:34 +01001336
Radek Krejci19a96102018-11-15 13:38:09 +01001337 free(module);
1338}
Michal Vasko33ff9422020-07-03 09:50:39 +02001339
Michal Vaskoc636ea42022-09-16 10:20:31 +02001340void
1341lysf_ctx_erase(struct lysf_ctx *ctx)
1342{
1343 struct lysc_ext *ext;
1344 uint32_t i;
1345
1346 for (i = 0; i < ctx->ext_set.count; ++i) {
1347 ext = ctx->ext_set.objs[i];
1348
1349 lydict_remove(ctx->ctx, ext->name);
1350 lydict_remove(ctx->ctx, ext->argname);
1351 free(ext);
1352 }
1353 ly_set_erase(&ctx->ext_set, NULL);
1354}
1355
Jan Kundrátc53a7ec2021-12-09 16:01:19 +01001356LIBYANG_API_DEF void
Radek Krejci0b013302021-03-29 15:22:32 +02001357lyplg_ext_instance_substatements_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts)
Radek Krejci38d85362019-09-05 16:26:38 +02001358{
Radek Krejci1b2eef82021-02-17 11:17:27 +01001359 LY_ARRAY_COUNT_TYPE u;
Michal Vaskoc636ea42022-09-16 10:20:31 +02001360 struct lysf_ctx fctx = {.ctx = ctx};
Radek Krejci1b2eef82021-02-17 11:17:27 +01001361
1362 LY_ARRAY_FOR(substmts, u) {
Radek Krejci38d85362019-09-05 16:26:38 +02001363 if (!substmts[u].storage) {
1364 continue;
1365 }
1366
Michal Vaskod989ba02020-08-24 10:59:24 +02001367 switch (substmts[u].stmt) {
Radek Krejci6b88a462021-02-17 12:39:34 +01001368 case LY_STMT_ACTION:
1369 case LY_STMT_ANYDATA:
1370 case LY_STMT_ANYXML:
1371 case LY_STMT_CONTAINER:
1372 case LY_STMT_CHOICE:
1373 case LY_STMT_LEAF:
1374 case LY_STMT_LEAF_LIST:
1375 case LY_STMT_LIST:
1376 case LY_STMT_NOTIFICATION:
Michal Vaskoedb0fa52022-10-04 10:36:00 +02001377 case LY_STMT_RPC: {
Radek Krejci6b88a462021-02-17 12:39:34 +01001378 struct lysc_node *child, *child_next;
1379
1380 LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) {
Michal Vaskoc636ea42022-09-16 10:20:31 +02001381 lysc_node_free_(&fctx, child);
Radek Krejci38d85362019-09-05 16:26:38 +02001382 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02001383 *((struct lysc_node **)substmts[u].storage) = NULL;
Radek Krejci38d85362019-09-05 16:26:38 +02001384 break;
Radek Krejci6b88a462021-02-17 12:39:34 +01001385 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02001386 case LY_STMT_GROUPING: {
1387 struct lysp_node_grp *grp, *grp_next;
1388
1389 LY_LIST_FOR_SAFE(*((struct lysp_node_grp **)substmts[u].storage), grp_next, grp) {
1390 lysp_node_free(&fctx, &grp->node);
1391 }
1392 break;
1393 }
1394 case LY_STMT_USES:
Radek Krejci6b88a462021-02-17 12:39:34 +01001395 case LY_STMT_CONFIG:
1396 case LY_STMT_STATUS:
1397 /* nothing to do */
1398 break;
Michal Vasko3ac60e52022-09-05 11:08:31 +02001399 case LY_STMT_CONTACT:
Radek Krejci1b2eef82021-02-17 11:17:27 +01001400 case LY_STMT_DESCRIPTION:
Michal Vasko3ac60e52022-09-05 11:08:31 +02001401 case LY_STMT_ERROR_APP_TAG:
1402 case LY_STMT_ERROR_MESSAGE:
1403 case LY_STMT_KEY:
1404 case LY_STMT_NAMESPACE:
1405 case LY_STMT_ORGANIZATION:
1406 case LY_STMT_PRESENCE:
Radek Krejci1b2eef82021-02-17 11:17:27 +01001407 case LY_STMT_REFERENCE:
Radek Krejci38d85362019-09-05 16:26:38 +02001408 case LY_STMT_UNITS:
1409 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
1410 /* single item */
Michal Vasko22df3f02020-08-24 13:29:22 +02001411 const char *str = *((const char **)substmts[u].storage);
Michal Vasko26bbb272022-08-02 14:54:33 +02001412
Michal Vaskoe180ed02021-02-05 16:31:20 +01001413 lydict_remove(ctx, str);
Radek Krejci38d85362019-09-05 16:26:38 +02001414 } else {
1415 /* multiple items */
Michal Vasko22df3f02020-08-24 13:29:22 +02001416 const char **strs = *((const char ***)substmts[u].storage);
Michal Vasko26bbb272022-08-02 14:54:33 +02001417
Radek Krejci38d85362019-09-05 16:26:38 +02001418 FREE_STRINGS(ctx, strs);
1419 }
1420 break;
Michal Vaskoedb0fa52022-10-04 10:36:00 +02001421 case LY_STMT_MUST:
1422 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
1423 /* single item */
1424 struct lysc_must *must = *((struct lysc_must **)substmts[u].storage);
1425
1426 lysc_must_free(&fctx, must);
1427 free(must);
1428 } else {
1429 /* multiple items */
1430 struct lysc_must *musts = *((struct lysc_must **)substmts[u].storage);
1431
1432 FREE_ARRAY(&fctx, musts, lysc_must_free);
1433 }
1434 break;
Radek Krejci38d85362019-09-05 16:26:38 +02001435 case LY_STMT_IF_FEATURE: {
Michal Vasko22df3f02020-08-24 13:29:22 +02001436 struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage);
Michal Vasko26bbb272022-08-02 14:54:33 +02001437
Radek Krejci38d85362019-09-05 16:26:38 +02001438 if (!iff) {
1439 break;
1440 }
1441 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
1442 /* single item */
Michal Vaskoc636ea42022-09-16 10:20:31 +02001443 lysc_iffeature_free(&fctx, iff);
Radek Krejci38d85362019-09-05 16:26:38 +02001444 free(iff);
1445 } else {
1446 /* multiple items */
Michal Vaskoc636ea42022-09-16 10:20:31 +02001447 FREE_ARRAY(&fctx, iff, lysc_iffeature_free);
Radek Krejci38d85362019-09-05 16:26:38 +02001448 }
1449 break;
1450 }
Michal Vaskoedb0fa52022-10-04 10:36:00 +02001451 case LY_STMT_TYPEDEF: {
1452 struct lysp_tpdf *tpdf = *((struct lysp_tpdf **)substmts[u].storage);
1453
1454 if (!tpdf) {
1455 break;
1456 }
1457 /* always an array */
1458 FREE_ARRAY(&fctx, tpdf, lysp_tpdf_free);
1459 break;
1460 }
Michal Vaskof8647fa2022-09-05 11:07:54 +02001461 case LY_STMT_TYPE:
1462 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
1463 /* single item */
1464 struct lysc_type *type = *((struct lysc_type **)substmts[u].storage);
1465
1466 if (!type) {
1467 break;
1468 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001469 lysc_type_free(&fctx, type);
Michal Vaskof8647fa2022-09-05 11:07:54 +02001470 } else {
1471 /* multiple items */
1472 struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage);
1473
1474 if (!types) {
1475 break;
1476 }
Michal Vaskoc636ea42022-09-16 10:20:31 +02001477 FREE_ARRAY(&fctx, types, lysc_type2_free);
Michal Vaskof8647fa2022-09-05 11:07:54 +02001478 }
1479 break;
Radek Krejci38d85362019-09-05 16:26:38 +02001480
Radek Krejci0f969882020-08-21 16:56:47 +02001481 /* TODO other statements */
Radek Krejci38d85362019-09-05 16:26:38 +02001482 default:
1483 LOGINT(ctx);
1484 }
1485 }
Radek Krejci1b2eef82021-02-17 11:17:27 +01001486
1487 LY_ARRAY_FREE(substmts);
Radek Krejci38d85362019-09-05 16:26:38 +02001488}
David Sedlákebd3acf2019-07-26 15:04:32 +02001489
1490void
Michal Vaskob36053d2020-03-26 15:49:30 +01001491yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx)
David Sedlákebd3acf2019-07-26 15:04:32 +02001492{
1493 if (ctx) {
aPiecek8d4e75d2021-06-24 14:47:06 +02001494 if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) {
1495 ly_set_erase(&ctx->tpdfs_nodes, NULL);
1496 ly_set_erase(&ctx->grps_nodes, NULL);
1497 }
Michal Vaskodd6d5a32022-07-14 13:54:58 +02001498 assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count);
Michal Vasko8a67eff2021-12-07 14:04:47 +01001499 ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL);
1500 if (!ctx->parsed_mods->count) {
1501 ly_set_free(ctx->parsed_mods, NULL);
1502 }
David Sedlákebd3acf2019-07-26 15:04:32 +02001503 free(ctx);
1504 }
1505}
1506
1507void
Michal Vaskob36053d2020-03-26 15:49:30 +01001508yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx)
David Sedlákebd3acf2019-07-26 15:04:32 +02001509{
1510 if (ctx) {
aPiecek8d4e75d2021-06-24 14:47:06 +02001511 if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) {
1512 ly_set_erase(&ctx->tpdfs_nodes, NULL);
1513 ly_set_erase(&ctx->grps_nodes, NULL);
1514 }
Michal Vaskodd6d5a32022-07-14 13:54:58 +02001515 assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count);
Michal Vasko8a67eff2021-12-07 14:04:47 +01001516 ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL);
1517 if (!ctx->parsed_mods->count) {
1518 ly_set_free(ctx->parsed_mods, NULL);
1519 }
Michal Vaskob36053d2020-03-26 15:49:30 +01001520 lyxml_ctx_free(ctx->xmlctx);
David Sedlákebd3acf2019-07-26 15:04:32 +02001521 free(ctx);
1522 }
1523}