blob: c6406bf0ce3b16e130d697b271f88a214c42fe79 [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>
Radek Krejcie7b95092019-05-15 11:03:07 +02004 * @brief Freeing functions for schema tree structures.
Radek Krejci19a96102018-11-15 13:38:09 +01005 *
Radek Krejcie7b95092019-05-15 11:03:07 +02006 * Copyright (c) 2019 CESNET, z.s.p.o.
Radek Krejci19a96102018-11-15 13:38:09 +01007 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#include "common.h"
16
Radek Krejcie7b95092019-05-15 11:03:07 +020017#include <stdlib.h>
18
19#include "dict.h"
20#include "tree.h"
21#include "tree_schema.h"
Radek Krejci19a96102018-11-15 13:38:09 +010022#include "tree_schema_internal.h"
Radek Krejcia1911222019-07-22 17:24:50 +020023#include "plugins_types.h"
Radek Krejci19a96102018-11-15 13:38:09 +010024#include "xpath.h"
25
Radek Krejci2d7a47b2019-05-16 13:34:10 +020026void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
27void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
Michal Vasko5fe75f12020-03-02 13:52:37 +010028void lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext);
Radek Krejci19a96102018-11-15 13:38:09 +010029
30static void
31lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt)
32{
33 struct lysp_stmt *child, *next;
34
35 FREE_STRING(ctx, stmt->stmt);
36 FREE_STRING(ctx, stmt->arg);
37
38 LY_LIST_FOR_SAFE(stmt->child, next, child) {
39 lysp_stmt_free(ctx, child);
40 }
41
42 free(stmt);
43}
44
Radek Krejci2d7a47b2019-05-16 13:34:10 +020045void
Radek Krejci19a96102018-11-15 13:38:09 +010046lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext)
47{
48 struct lysp_stmt *stmt, *next;
49
50 FREE_STRING(ctx, ext->name);
51 FREE_STRING(ctx, ext->argument);
52
53 LY_LIST_FOR_SAFE(ext->child, next, stmt) {
54 lysp_stmt_free(ctx, stmt);
55 }
56}
57
David Sedlák298ff6d2019-07-26 14:29:03 +020058void
Radek Krejci19a96102018-11-15 13:38:09 +010059lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import)
60{
61 /* imported module is freed directly from the context's list */
62 FREE_STRING(ctx, import->name);
63 FREE_STRING(ctx, import->prefix);
64 FREE_STRING(ctx, import->dsc);
65 FREE_STRING(ctx, import->ref);
66 FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free);
67}
68
David Sedlák0c2bab92019-07-22 15:33:19 +020069void
Radek Krejci19a96102018-11-15 13:38:09 +010070lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include)
71{
72 if (include->submodule) {
Radek Krejci0bcdaed2019-01-10 10:21:34 +010073 lysp_submodule_free(ctx, include->submodule);
Radek Krejci19a96102018-11-15 13:38:09 +010074 }
75 FREE_STRING(ctx, include->name);
76 FREE_STRING(ctx, include->dsc);
77 FREE_STRING(ctx, include->ref);
78 FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free);
79}
80
David Sedlákaa854b02019-07-22 14:17:10 +020081void
Radek Krejci19a96102018-11-15 13:38:09 +010082lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev)
83{
84 FREE_STRING(ctx, rev->dsc);
85 FREE_STRING(ctx, rev->ref);
86 FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free);
87}
88
David Sedlák986cb412019-07-04 13:10:11 +020089void
Radek Krejci19a96102018-11-15 13:38:09 +010090lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext)
91{
92 FREE_STRING(ctx, ext->name);
93 FREE_STRING(ctx, ext->argument);
94 FREE_STRING(ctx, ext->dsc);
95 FREE_STRING(ctx, ext->ref);
96 FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free);
Michal Vasko5fe75f12020-03-02 13:52:37 +010097 if (ext->compiled) {
98 lysc_extension_free(ctx, &ext->compiled);
99 }
Radek Krejci19a96102018-11-15 13:38:09 +0100100}
101
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200102void
Radek Krejci19a96102018-11-15 13:38:09 +0100103lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat)
104{
105 FREE_STRING(ctx, feat->name);
106 FREE_STRINGS(ctx, feat->iffeatures);
107 FREE_STRING(ctx, feat->dsc);
108 FREE_STRING(ctx, feat->ref);
109 FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free);
110}
111
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200112void
Radek Krejci19a96102018-11-15 13:38:09 +0100113lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident)
114{
115 FREE_STRING(ctx, ident->name);
116 FREE_STRINGS(ctx, ident->iffeatures);
117 FREE_STRINGS(ctx, ident->bases);
118 FREE_STRING(ctx, ident->dsc);
119 FREE_STRING(ctx, ident->ref);
120 FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free);
121}
122
123static void
124lysp_restr_free(struct ly_ctx *ctx, struct lysp_restr *restr)
125{
126 FREE_STRING(ctx, restr->arg);
127 FREE_STRING(ctx, restr->emsg);
128 FREE_STRING(ctx, restr->eapptag);
129 FREE_STRING(ctx, restr->dsc);
130 FREE_STRING(ctx, restr->ref);
131 FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free);
132}
133
134static void
135lysp_type_enum_free(struct ly_ctx *ctx, struct lysp_type_enum *item)
136{
137 FREE_STRING(ctx, item->name);
138 FREE_STRING(ctx, item->dsc);
139 FREE_STRING(ctx, item->ref);
140 FREE_STRINGS(ctx, item->iffeatures);
141 FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free);
142}
143
Radek Krejcicdfecd92018-11-26 11:27:32 +0100144void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type);
David Sedlák32488102019-07-15 17:44:10 +0200145void
Radek Krejci19a96102018-11-15 13:38:09 +0100146lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type)
147{
148 FREE_STRING(ctx, type->name);
149 FREE_MEMBER(ctx, type->range, lysp_restr_free);
150 FREE_MEMBER(ctx, type->length, lysp_restr_free);
151 FREE_ARRAY(ctx, type->patterns, lysp_restr_free);
152 FREE_ARRAY(ctx, type->enums, lysp_type_enum_free);
153 FREE_ARRAY(ctx, type->bits, lysp_type_enum_free);
154 FREE_STRING(ctx, type->path);
155 FREE_STRINGS(ctx, type->bases);
156 FREE_ARRAY(ctx, type->types, lysp_type_free);
157 FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free);
158 if (type->compiled) {
159 lysc_type_free(ctx, type->compiled);
160 }
161}
162
David Sedlák04e17b22019-07-19 15:29:48 +0200163void
Radek Krejci19a96102018-11-15 13:38:09 +0100164lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf)
165{
166 FREE_STRING(ctx, tpdf->name);
167 FREE_STRING(ctx, tpdf->units);
168 FREE_STRING(ctx, tpdf->dflt);
169 FREE_STRING(ctx, tpdf->dsc);
170 FREE_STRING(ctx, tpdf->ref);
171 FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free);
172
173 lysp_type_free(ctx, &tpdf->type);
174
175}
176
Radek Krejcif538ce52019-03-05 10:46:14 +0100177void
Radek Krejci19a96102018-11-15 13:38:09 +0100178lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout)
179{
180 struct lysp_node *node, *next;
181
182 FREE_ARRAY(ctx, inout->musts, lysp_restr_free);
183 FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free);
184 FREE_ARRAY(ctx, inout->groupings, lysp_grp_free);
185 LY_LIST_FOR_SAFE(inout->data, next, node) {
186 lysp_node_free(ctx, node);
187 }
188 FREE_ARRAY(ctx, inout->exts, lysp_ext_instance_free);
189
190}
191
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200192void
Radek Krejci19a96102018-11-15 13:38:09 +0100193lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action)
194{
195 FREE_STRING(ctx, action->name);
196 FREE_STRING(ctx, action->dsc);
197 FREE_STRING(ctx, action->ref);
198 FREE_STRINGS(ctx, action->iffeatures);
199 FREE_ARRAY(ctx, action->typedefs, lysp_tpdf_free);
200 FREE_ARRAY(ctx, action->groupings, lysp_grp_free);
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100201 lysp_action_inout_free(ctx, &action->input);
202 lysp_action_inout_free(ctx, &action->output);
Radek Krejci19a96102018-11-15 13:38:09 +0100203 FREE_ARRAY(ctx, action->exts, lysp_ext_instance_free);
204}
205
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200206void
Radek Krejci19a96102018-11-15 13:38:09 +0100207lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif)
208{
209 struct lysp_node *node, *next;
210
211 FREE_STRING(ctx, notif->name);
212 FREE_STRING(ctx, notif->dsc);
213 FREE_STRING(ctx, notif->ref);
214 FREE_STRINGS(ctx, notif->iffeatures);
215 FREE_ARRAY(ctx, notif->musts, lysp_restr_free);
216 FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free);
217 FREE_ARRAY(ctx, notif->groupings, lysp_grp_free);
218 LY_LIST_FOR_SAFE(notif->data, next, node) {
219 lysp_node_free(ctx, node);
220 }
221 FREE_ARRAY(ctx, notif->exts, lysp_ext_instance_free);
222}
223
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200224void
Radek Krejci19a96102018-11-15 13:38:09 +0100225lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp)
226{
227 struct lysp_node *node, *next;
228
229 FREE_STRING(ctx, grp->name);
230 FREE_STRING(ctx, grp->dsc);
231 FREE_STRING(ctx, grp->ref);
232 FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free);
233 FREE_ARRAY(ctx, grp->groupings, lysp_grp_free);
234 LY_LIST_FOR_SAFE(grp->data, next, node) {
235 lysp_node_free(ctx, node);
236 }
237 FREE_ARRAY(ctx, grp->actions, lysp_action_free);
238 FREE_ARRAY(ctx, grp->notifs, lysp_notif_free);
239 FREE_ARRAY(ctx, grp->exts, lysp_ext_instance_free);
240}
241
Radek Krejcif09e4e82019-06-14 15:08:11 +0200242void
Radek Krejci19a96102018-11-15 13:38:09 +0100243lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when)
244{
245 FREE_STRING(ctx, when->cond);
246 FREE_STRING(ctx, when->dsc);
247 FREE_STRING(ctx, when->ref);
248 FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free);
249}
250
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200251void
Radek Krejci19a96102018-11-15 13:38:09 +0100252lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment)
253{
254 struct lysp_node *node, *next;
255
256 FREE_STRING(ctx, augment->nodeid);
257 FREE_STRING(ctx, augment->dsc);
258 FREE_STRING(ctx, augment->ref);
259 FREE_MEMBER(ctx, augment->when, lysp_when_free);
260 FREE_STRINGS(ctx, augment->iffeatures);
261 LY_LIST_FOR_SAFE(augment->child, next, node) {
262 lysp_node_free(ctx, node);
263 }
264 FREE_ARRAY(ctx, augment->actions, lysp_action_free);
265 FREE_ARRAY(ctx, augment->notifs, lysp_notif_free);
266 FREE_ARRAY(ctx, augment->exts, lysp_ext_instance_free);
267}
268
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200269void
Radek Krejci19a96102018-11-15 13:38:09 +0100270lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d)
271{
272 struct lysp_deviate_add *add = (struct lysp_deviate_add*)d;
273 struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl*)d;
274
275 FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free);
276 switch(d->mod) {
277 case LYS_DEV_NOT_SUPPORTED:
278 /* nothing to do */
279 break;
280 case LYS_DEV_ADD:
281 case LYS_DEV_DELETE: /* compatible for dynamically allocated data */
282 FREE_STRING(ctx, add->units);
283 FREE_ARRAY(ctx, add->musts, lysp_restr_free);
284 FREE_STRINGS(ctx, add->uniques);
285 FREE_STRINGS(ctx, add->dflts);
286 break;
287 case LYS_DEV_REPLACE:
288 FREE_MEMBER(ctx, rpl->type, lysp_type_free);
289 FREE_STRING(ctx, rpl->units);
290 FREE_STRING(ctx, rpl->dflt);
291 break;
292 default:
293 LOGINT(ctx);
294 break;
295 }
296}
297
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200298void
Radek Krejci19a96102018-11-15 13:38:09 +0100299lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev)
300{
301 struct lysp_deviate *next, *iter;
302
303 FREE_STRING(ctx, dev->nodeid);
304 FREE_STRING(ctx, dev->dsc);
305 FREE_STRING(ctx, dev->ref);
306 LY_LIST_FOR_SAFE(dev->deviates, next, iter) {
307 lysp_deviate_free(ctx, iter);
308 free(iter);
309 }
310 FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free);
311}
312
David Sedlákd2d676a2019-07-22 11:28:19 +0200313void
Radek Krejci19a96102018-11-15 13:38:09 +0100314lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref)
315{
316 FREE_STRING(ctx, ref->nodeid);
317 FREE_STRING(ctx, ref->dsc);
318 FREE_STRING(ctx, ref->ref);
319 FREE_STRINGS(ctx, ref->iffeatures);
320 FREE_ARRAY(ctx, ref->musts, lysp_restr_free);
321 FREE_STRING(ctx, ref->presence);
322 FREE_STRINGS(ctx, ref->dflts);
323 FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free);
324}
325
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200326void
Radek Krejci19a96102018-11-15 13:38:09 +0100327lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node)
328{
329 struct lysp_node *child, *next;
330
331 FREE_STRING(ctx, node->name);
332 FREE_STRING(ctx, node->dsc);
333 FREE_STRING(ctx, node->ref);
334 FREE_MEMBER(ctx, node->when, lysp_when_free);
335 FREE_STRINGS(ctx, node->iffeatures);
336 FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free);
337
338 switch(node->nodetype) {
339 case LYS_CONTAINER:
340 FREE_ARRAY(ctx, ((struct lysp_node_container*)node)->musts, lysp_restr_free);
341 FREE_STRING(ctx, ((struct lysp_node_container*)node)->presence);
342 FREE_ARRAY(ctx, ((struct lysp_node_container*)node)->typedefs, lysp_tpdf_free);
343 FREE_ARRAY(ctx, ((struct lysp_node_container*)node)->groupings, lysp_grp_free);
344 LY_LIST_FOR_SAFE(((struct lysp_node_container*)node)->child, next, child) {
345 lysp_node_free(ctx, child);
346 }
347 FREE_ARRAY(ctx, ((struct lysp_node_container*)node)->actions, lysp_action_free);
348 FREE_ARRAY(ctx, ((struct lysp_node_container*)node)->notifs, lysp_notif_free);
349 break;
350 case LYS_LEAF:
351 FREE_ARRAY(ctx, ((struct lysp_node_leaf*)node)->musts, lysp_restr_free);
352 lysp_type_free(ctx, &((struct lysp_node_leaf*)node)->type);
353 FREE_STRING(ctx, ((struct lysp_node_leaf*)node)->units);
354 FREE_STRING(ctx, ((struct lysp_node_leaf*)node)->dflt);
355 break;
356 case LYS_LEAFLIST:
357 FREE_ARRAY(ctx, ((struct lysp_node_leaflist*)node)->musts, lysp_restr_free);
358 lysp_type_free(ctx, &((struct lysp_node_leaflist*)node)->type);
359 FREE_STRING(ctx, ((struct lysp_node_leaflist*)node)->units);
360 FREE_STRINGS(ctx, ((struct lysp_node_leaflist*)node)->dflts);
361 break;
362 case LYS_LIST:
363 FREE_ARRAY(ctx, ((struct lysp_node_list*)node)->musts, lysp_restr_free);
364 FREE_STRING(ctx, ((struct lysp_node_list*)node)->key);
365 FREE_ARRAY(ctx, ((struct lysp_node_list*)node)->typedefs, lysp_tpdf_free);
366 FREE_ARRAY(ctx, ((struct lysp_node_list*)node)->groupings, lysp_grp_free);
367 LY_LIST_FOR_SAFE(((struct lysp_node_list*)node)->child, next, child) {
368 lysp_node_free(ctx, child);
369 }
370 FREE_ARRAY(ctx, ((struct lysp_node_list*)node)->actions, lysp_action_free);
371 FREE_ARRAY(ctx, ((struct lysp_node_list*)node)->notifs, lysp_notif_free);
372 FREE_STRINGS(ctx, ((struct lysp_node_list*)node)->uniques);
373 break;
374 case LYS_CHOICE:
375 LY_LIST_FOR_SAFE(((struct lysp_node_choice*)node)->child, next, child) {
376 lysp_node_free(ctx, child);
377 }
378 FREE_STRING(ctx, ((struct lysp_node_choice*)node)->dflt);
379 break;
380 case LYS_CASE:
381 LY_LIST_FOR_SAFE(((struct lysp_node_case*)node)->child, next, child) {
382 lysp_node_free(ctx, child);
383 }
384 break;
385 case LYS_ANYDATA:
386 case LYS_ANYXML:
387 FREE_ARRAY(ctx, ((struct lysp_node_anydata*)node)->musts, lysp_restr_free);
388 break;
389 case LYS_USES:
390 FREE_ARRAY(ctx, ((struct lysp_node_uses*)node)->refines, lysp_refine_free);
391 FREE_ARRAY(ctx, ((struct lysp_node_uses*)node)->augments, lysp_augment_free);
392 break;
393 default:
394 LOGINT(ctx);
395 }
396
397 free(node);
398}
399
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100400void
401lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod)
402{
403 struct lysp_node *node, *next;
404
Radek Krejci40544fa2019-01-11 09:38:37 +0100405 if (!submod) {
406 return;
407 }
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100408
409 FREE_ARRAY(ctx, submod->imports, lysp_import_free);
410 FREE_ARRAY(ctx, submod->includes, lysp_include_free);
411
412 FREE_ARRAY(ctx, submod->revs, lysp_revision_free);
413 FREE_ARRAY(ctx, submod->extensions, lysp_ext_free);
414 FREE_ARRAY(ctx, submod->features, lysp_feature_free);
415 FREE_ARRAY(ctx, submod->identities, lysp_ident_free);
416 FREE_ARRAY(ctx, submod->typedefs, lysp_tpdf_free);
417 FREE_ARRAY(ctx, submod->groupings, lysp_grp_free);
418 LY_LIST_FOR_SAFE(submod->data, next, node) {
419 lysp_node_free(ctx, node);
420 }
421 FREE_ARRAY(ctx, submod->augments, lysp_augment_free);
422 FREE_ARRAY(ctx, submod->rpcs, lysp_action_free);
423 FREE_ARRAY(ctx, submod->notifs, lysp_notif_free);
424 FREE_ARRAY(ctx, submod->deviations, lysp_deviation_free);
425 FREE_ARRAY(ctx, submod->exts, lysp_ext_instance_free);
426
427 FREE_STRING(ctx, submod->belongsto);
428 FREE_STRING(ctx, submod->name);
429 FREE_STRING(ctx, submod->filepath);
430 FREE_STRING(ctx, submod->prefix);
431 FREE_STRING(ctx, submod->org);
432 FREE_STRING(ctx, submod->contact);
433 FREE_STRING(ctx, submod->dsc);
434 FREE_STRING(ctx, submod->ref);
435
436 free(submod);
437}
438
Radek Krejci19a96102018-11-15 13:38:09 +0100439API void
440lysp_module_free(struct lysp_module *module)
441{
442 struct ly_ctx *ctx;
443 struct lysp_node *node, *next;
444
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100445 if (!module) {
446 return;
447 }
448 ctx = module->mod->ctx;
Radek Krejci19a96102018-11-15 13:38:09 +0100449
450 FREE_ARRAY(ctx, module->imports, lysp_import_free);
451 FREE_ARRAY(ctx, module->includes, lysp_include_free);
452
Radek Krejci19a96102018-11-15 13:38:09 +0100453 FREE_ARRAY(ctx, module->revs, lysp_revision_free);
454 FREE_ARRAY(ctx, module->extensions, lysp_ext_free);
455 FREE_ARRAY(ctx, module->features, lysp_feature_free);
456 FREE_ARRAY(ctx, module->identities, lysp_ident_free);
457 FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free);
458 FREE_ARRAY(ctx, module->groupings, lysp_grp_free);
459 LY_LIST_FOR_SAFE(module->data, next, node) {
460 lysp_node_free(ctx, node);
461 }
462 FREE_ARRAY(ctx, module->augments, lysp_augment_free);
463 FREE_ARRAY(ctx, module->rpcs, lysp_action_free);
464 FREE_ARRAY(ctx, module->notifs, lysp_notif_free);
465 FREE_ARRAY(ctx, module->deviations, lysp_deviation_free);
466 FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free);
467
468 free(module);
469}
470
Radek Krejci0af46292019-01-11 16:02:31 +0100471void
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100472lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext)
473{
474 if (--(*ext)->refcount) {
475 return;
476 }
477 FREE_STRING(ctx, (*ext)->name);
478 FREE_STRING(ctx, (*ext)->argument);
479 FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free);
480 free(*ext);
481}
482
483void
Radek Krejci19a96102018-11-15 13:38:09 +0100484lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext)
485{
fredganebc50572019-10-31 15:39:23 +0800486 if (ext->def && ext->def->plugin && ext->def->plugin->free) {
Radek Krejci38d85362019-09-05 16:26:38 +0200487 ext->def->plugin->free(ctx, ext);
488 }
Juraj Vijtiuk4a19ab02020-03-03 13:50:14 +0100489 if (ext->def) {
490 lysc_extension_free(ctx, &ext->def);
491 }
Radek Krejci0935f412019-08-20 16:15:18 +0200492 FREE_STRING(ctx, ext->argument);
493 FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free);
494}
495
496void
Radek Krejci19a96102018-11-15 13:38:09 +0100497lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff)
498{
499 LY_ARRAY_FREE(iff->features);
500 free(iff->expr);
501}
502
503static void
Radek Krejci00b874b2019-02-12 10:54:50 +0100504lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w)
Radek Krejci58d171e2018-11-23 13:50:55 +0100505{
Radek Krejci00b874b2019-02-12 10:54:50 +0100506 if (--(*w)->refcount) {
507 return;
508 }
509 lyxp_expr_free(ctx, (*w)->cond);
510 FREE_STRING(ctx, (*w)->dsc);
511 FREE_STRING(ctx, (*w)->ref);
512 FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free);
513 free(*w);
Radek Krejci58d171e2018-11-23 13:50:55 +0100514}
515
Radek Krejciccd20f12019-02-15 14:12:27 +0100516void
Radek Krejci58d171e2018-11-23 13:50:55 +0100517lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must)
518{
519 lyxp_expr_free(ctx, must->cond);
520 FREE_STRING(ctx, must->emsg);
521 FREE_STRING(ctx, must->eapptag);
Radek Krejcic8b31002019-01-08 10:24:45 +0100522 FREE_STRING(ctx, must->dsc);
523 FREE_STRING(ctx, must->ref);
Radek Krejci58d171e2018-11-23 13:50:55 +0100524 FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free);
525}
526
527static void
Radek Krejci19a96102018-11-15 13:38:09 +0100528lysc_import_free(struct ly_ctx *ctx, struct lysc_import *import)
529{
530 /* imported module is freed directly from the context's list */
531 FREE_STRING(ctx, import->prefix);
532 FREE_ARRAY(ctx, import->exts, lysc_ext_instance_free);
533}
534
535static void
536lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident)
537{
538 FREE_STRING(ctx, ident->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100539 FREE_STRING(ctx, ident->dsc);
540 FREE_STRING(ctx, ident->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100541 FREE_ARRAY(ctx, ident->iffeatures, lysc_iffeature_free);
542 LY_ARRAY_FREE(ident->derived);
543 FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free);
544}
545
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200546void
Radek Krejci19a96102018-11-15 13:38:09 +0100547lysc_feature_free(struct ly_ctx *ctx, struct lysc_feature *feat)
548{
549 FREE_STRING(ctx, feat->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100550 FREE_STRING(ctx, feat->dsc);
551 FREE_STRING(ctx, feat->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100552 FREE_ARRAY(ctx, feat->iffeatures, lysc_iffeature_free);
553 LY_ARRAY_FREE(feat->depfeatures);
554 FREE_ARRAY(ctx, feat->exts, lysc_ext_instance_free);
555}
556
557static void
558lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range)
559{
560 LY_ARRAY_FREE(range->parts);
561 FREE_STRING(ctx, range->eapptag);
562 FREE_STRING(ctx, range->emsg);
Radek Krejcic8b31002019-01-08 10:24:45 +0100563 FREE_STRING(ctx, range->dsc);
564 FREE_STRING(ctx, range->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100565 FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free);
566}
567
568static void
569lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern)
570{
571 if (--(*pattern)->refcount) {
572 return;
573 }
Radek Krejci54579462019-04-30 12:47:06 +0200574 pcre2_code_free((*pattern)->code);
575 FREE_STRING(ctx, (*pattern)->expr);
Radek Krejci19a96102018-11-15 13:38:09 +0100576 FREE_STRING(ctx, (*pattern)->eapptag);
577 FREE_STRING(ctx, (*pattern)->emsg);
Radek Krejcic8b31002019-01-08 10:24:45 +0100578 FREE_STRING(ctx, (*pattern)->dsc);
579 FREE_STRING(ctx, (*pattern)->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100580 FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free);
581 free(*pattern);
582}
583
584static void
Radek Krejci693262f2019-04-29 15:23:20 +0200585lysc_enum_item_free(struct ly_ctx *ctx, struct lysc_type_bitenum_item *item)
Radek Krejci19a96102018-11-15 13:38:09 +0100586{
587 FREE_STRING(ctx, item->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100588 FREE_STRING(ctx, item->dsc);
589 FREE_STRING(ctx, item->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100590 FREE_ARRAY(ctx, item->iffeatures, lysc_iffeature_free);
591 FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free);
592}
593
Radek Krejcia3045382018-11-22 14:30:31 +0100594static void
595lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type)
596{
597 lysc_type_free(ctx, *type);
598}
Radek Krejcicdfecd92018-11-26 11:27:32 +0100599void
Radek Krejci19a96102018-11-15 13:38:09 +0100600lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type)
601{
602 if (--type->refcount) {
603 return;
604 }
605 switch(type->basetype) {
606 case LY_TYPE_BINARY:
607 FREE_MEMBER(ctx, ((struct lysc_type_bin*)type)->length, lysc_range_free);
608 break;
609 case LY_TYPE_BITS:
Radek Krejci693262f2019-04-29 15:23:20 +0200610 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 +0100611 break;
Radek Krejci6cba4292018-11-15 17:33:29 +0100612 case LY_TYPE_DEC64:
613 FREE_MEMBER(ctx, ((struct lysc_type_dec*)type)->range, lysc_range_free);
614 break;
Radek Krejci19a96102018-11-15 13:38:09 +0100615 case LY_TYPE_STRING:
616 FREE_MEMBER(ctx, ((struct lysc_type_str*)type)->length, lysc_range_free);
617 FREE_ARRAY(ctx, ((struct lysc_type_str*)type)->patterns, lysc_pattern_free);
618 break;
619 case LY_TYPE_ENUM:
620 FREE_ARRAY(ctx, ((struct lysc_type_enum*)type)->enums, lysc_enum_item_free);
621 break;
622 case LY_TYPE_INT8:
623 case LY_TYPE_UINT8:
624 case LY_TYPE_INT16:
625 case LY_TYPE_UINT16:
626 case LY_TYPE_INT32:
627 case LY_TYPE_UINT32:
628 case LY_TYPE_INT64:
629 case LY_TYPE_UINT64:
630 FREE_MEMBER(ctx, ((struct lysc_type_num*)type)->range, lysc_range_free);
631 break;
Radek Krejci555cb5b2018-11-16 14:54:33 +0100632 case LY_TYPE_IDENT:
633 LY_ARRAY_FREE(((struct lysc_type_identityref*)type)->bases);
634 break;
Radek Krejcia3045382018-11-22 14:30:31 +0100635 case LY_TYPE_UNION:
636 FREE_ARRAY(ctx, ((struct lysc_type_union*)type)->types, lysc_type2_free);
637 break;
638 case LY_TYPE_LEAFREF:
639 FREE_STRING(ctx, ((struct lysc_type_leafref*)type)->path);
640 break;
Radek Krejci16c0f822018-11-16 10:46:10 +0100641 case LY_TYPE_INST:
Radek Krejci19a96102018-11-15 13:38:09 +0100642 case LY_TYPE_BOOL:
643 case LY_TYPE_EMPTY:
Radek Krejci43699232018-11-23 14:59:46 +0100644 case LY_TYPE_UNKNOWN:
Radek Krejci19a96102018-11-15 13:38:09 +0100645 /* nothing to do */
646 break;
647 }
648 FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
Radek Krejcia1911222019-07-22 17:24:50 +0200649 if (type->dflt) {
650 type->plugin->free(ctx, type->dflt);
651 lysc_type_free(ctx, type->dflt->realtype);
652 free(type->dflt);
653 }
Radek Krejci19a96102018-11-15 13:38:09 +0100654 free(type);
655}
656
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100657void
Radek Krejcif538ce52019-03-05 10:46:14 +0100658lysc_action_inout_free(struct ly_ctx *ctx, struct lysc_action_inout *inout)
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100659{
660 struct lysc_node *child, *child_next;
661
Radek Krejcif538ce52019-03-05 10:46:14 +0100662 FREE_ARRAY(ctx, inout->musts, lysc_must_free);
663 LY_LIST_FOR_SAFE(inout->data, child_next, child) {
664 lysc_node_free(ctx, child);
665 }
666}
667
668void
669lysc_action_free(struct ly_ctx *ctx, struct lysc_action *action)
670{
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100671 FREE_STRING(ctx, action->name);
672 FREE_STRING(ctx, action->dsc);
673 FREE_STRING(ctx, action->ref);
674 FREE_ARRAY(ctx, action->iffeatures, lysc_iffeature_free);
675 FREE_ARRAY(ctx, action->exts, lysc_ext_instance_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200676 FREE_ARRAY(ctx, action->input_exts, lysc_ext_instance_free);
Radek Krejcif538ce52019-03-05 10:46:14 +0100677 lysc_action_inout_free(ctx, &action->input);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200678 FREE_ARRAY(ctx, action->output_exts, lysc_ext_instance_free);
Radek Krejcif538ce52019-03-05 10:46:14 +0100679 lysc_action_inout_free(ctx, &action->output);
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100680}
681
Radek Krejcifc11bd72019-04-11 16:00:05 +0200682void
683lysc_notif_free(struct ly_ctx *ctx, struct lysc_notif *notif)
684{
685 struct lysc_node *child, *child_next;
686
687 FREE_STRING(ctx, notif->name);
688 FREE_STRING(ctx, notif->dsc);
689 FREE_STRING(ctx, notif->ref);
690 FREE_ARRAY(ctx, notif->iffeatures, lysc_iffeature_free);
691 FREE_ARRAY(ctx, notif->exts, lysc_ext_instance_free);
692 FREE_ARRAY(ctx, notif->musts, lysc_must_free);
693 LY_LIST_FOR_SAFE(notif->data, child_next, child) {
694 lysc_node_free(ctx, child);
695 }
696}
697
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200698void
Radek Krejci19a96102018-11-15 13:38:09 +0100699lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node)
700{
701 struct lysc_node *child, *child_next;
702
703 LY_LIST_FOR_SAFE(node->child, child_next, child) {
704 lysc_node_free(ctx, child);
705 }
Radek Krejci58d171e2018-11-23 13:50:55 +0100706 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100707 FREE_ARRAY(ctx, node->actions, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200708 FREE_ARRAY(ctx, node->notifs, lysc_notif_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100709}
710
711static void
712lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node)
713{
Radek Krejci58d171e2018-11-23 13:50:55 +0100714 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100715 if (node->type) {
716 lysc_type_free(ctx, node->type);
717 }
Radek Krejci58d171e2018-11-23 13:50:55 +0100718 FREE_STRING(ctx, node->units);
Radek Krejcia1911222019-07-22 17:24:50 +0200719 if (node->dflt) {
720 node->dflt->realtype->plugin->free(ctx, node->dflt);
721 lysc_type_free(ctx, node->dflt->realtype);
722 free(node->dflt);
723 }
Radek Krejci19a96102018-11-15 13:38:09 +0100724}
725
Radek Krejci42452ac2018-11-28 17:09:52 +0100726static void
727lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node)
728{
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200729 LY_ARRAY_SIZE_TYPE u;
Radek Krejci42452ac2018-11-28 17:09:52 +0100730
Radek Krejci42452ac2018-11-28 17:09:52 +0100731 FREE_ARRAY(ctx, node->musts, lysc_must_free);
732 if (node->type) {
733 lysc_type_free(ctx, node->type);
734 }
735 FREE_STRING(ctx, node->units);
736 LY_ARRAY_FOR(node->dflts, u) {
Radek Krejcia1911222019-07-22 17:24:50 +0200737 node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]);
738 lysc_type_free(ctx, node->dflts[u]->realtype);
739 free(node->dflts[u]);
Radek Krejci42452ac2018-11-28 17:09:52 +0100740 }
741 LY_ARRAY_FREE(node->dflts);
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200742 LY_ARRAY_FREE(node->dflts_mods);
Radek Krejci42452ac2018-11-28 17:09:52 +0100743}
744
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100745static void
746lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node)
747{
Radek Krejci7eb54ba2020-05-18 16:30:04 +0200748 LY_ARRAY_SIZE_TYPE u;
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100749 struct lysc_node *child, *child_next;
750
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100751 LY_LIST_FOR_SAFE(node->child, child_next, child) {
752 lysc_node_free(ctx, child);
753 }
754 FREE_ARRAY(ctx, node->musts, lysc_must_free);
755
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100756 LY_ARRAY_FOR(node->uniques, u) {
757 LY_ARRAY_FREE(node->uniques[u]);
758 }
759 LY_ARRAY_FREE(node->uniques);
760
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100761 FREE_ARRAY(ctx, node->actions, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200762 FREE_ARRAY(ctx, node->notifs, lysc_notif_free);
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100763}
764
Radek Krejci056d0a82018-12-06 16:57:25 +0100765static void
766lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node)
767{
768 struct lysc_node *child, *child_next;
769
Radek Krejci056d0a82018-12-06 16:57:25 +0100770 if (node->cases) {
771 LY_LIST_FOR_SAFE(node->cases->child, child_next, child) {
772 lysc_node_free(ctx, child);
773 }
774 LY_LIST_FOR_SAFE((struct lysc_node*)node->cases, child_next, child) {
775 lysc_node_free(ctx, child);
776 }
777 }
Radek Krejci9800fb82018-12-13 14:26:23 +0100778}
Radek Krejci056d0a82018-12-06 16:57:25 +0100779
Radek Krejci9800fb82018-12-13 14:26:23 +0100780static void
781lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node)
782{
783 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci056d0a82018-12-06 16:57:25 +0100784}
785
Radek Krejci19a96102018-11-15 13:38:09 +0100786void
787lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node)
788{
789 /* common part */
790 FREE_STRING(ctx, node->name);
Radek Krejci12fb9142019-01-08 09:45:30 +0100791 FREE_STRING(ctx, node->dsc);
792 FREE_STRING(ctx, node->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100793
794 /* nodetype-specific part */
795 switch(node->nodetype) {
796 case LYS_CONTAINER:
797 lysc_node_container_free(ctx, (struct lysc_node_container*)node);
798 break;
799 case LYS_LEAF:
800 lysc_node_leaf_free(ctx, (struct lysc_node_leaf*)node);
801 break;
Radek Krejci42452ac2018-11-28 17:09:52 +0100802 case LYS_LEAFLIST:
803 lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist*)node);
804 break;
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100805 case LYS_LIST:
806 lysc_node_list_free(ctx, (struct lysc_node_list*)node);
807 break;
Radek Krejci056d0a82018-12-06 16:57:25 +0100808 case LYS_CHOICE:
809 lysc_node_choice_free(ctx, (struct lysc_node_choice*)node);
810 break;
811 case LYS_CASE:
812 /* nothing specific */
813 break;
Radek Krejci9800fb82018-12-13 14:26:23 +0100814 case LYS_ANYDATA:
815 case LYS_ANYXML:
816 lysc_node_anydata_free(ctx, (struct lysc_node_anydata*)node);
817 break;
Radek Krejci19a96102018-11-15 13:38:09 +0100818 default:
819 LOGINT(ctx);
820 }
821
Radek Krejci00b874b2019-02-12 10:54:50 +0100822 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci056d0a82018-12-06 16:57:25 +0100823 FREE_ARRAY(ctx, node->iffeatures, lysc_iffeature_free);
824 FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100825 free(node);
826}
827
828static void
829lysc_module_free_(struct lysc_module *module)
830{
831 struct ly_ctx *ctx;
832 struct lysc_node *node, *node_next;
833
834 LY_CHECK_ARG_RET(NULL, module,);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100835 ctx = module->mod->ctx;
Radek Krejci19a96102018-11-15 13:38:09 +0100836
Radek Krejci19a96102018-11-15 13:38:09 +0100837 FREE_ARRAY(ctx, module->imports, lysc_import_free);
838 FREE_ARRAY(ctx, module->features, lysc_feature_free);
839 FREE_ARRAY(ctx, module->identities, lysc_ident_free);
840
841 LY_LIST_FOR_SAFE(module->data, node_next, node) {
842 lysc_node_free(ctx, node);
843 }
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100844 FREE_ARRAY(ctx, module->rpcs, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200845 FREE_ARRAY(ctx, module->notifs, lysc_notif_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100846 FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free);
847
848 free(module);
849}
850
851void
852lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv))
853{
Radek Krejci9b042892019-02-13 14:28:44 +0100854 /* TODO use the destructor, this just suppress warning about unused parameter */
855 (void) private_destructor;
856
Radek Krejci19a96102018-11-15 13:38:09 +0100857 if (module) {
858 lysc_module_free_(module);
859 }
860}
861
862void
863lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv))
864{
865 if (!module) {
866 return;
867 }
868
869 lysc_module_free(module->compiled, private_destructor);
Radek Krejci0af46292019-01-11 16:02:31 +0100870 FREE_ARRAY(module->ctx, module->off_features, lysc_feature_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100871 lysp_module_free(module->parsed);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100872
873 FREE_STRING(module->ctx, module->name);
Radek Krejci0af46292019-01-11 16:02:31 +0100874 FREE_STRING(module->ctx, module->revision);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100875 FREE_STRING(module->ctx, module->ns);
876 FREE_STRING(module->ctx, module->prefix);
877 FREE_STRING(module->ctx, module->filepath);
878 FREE_STRING(module->ctx, module->org);
879 FREE_STRING(module->ctx, module->contact);
880 FREE_STRING(module->ctx, module->dsc);
881 FREE_STRING(module->ctx, module->ref);
882
Radek Krejci19a96102018-11-15 13:38:09 +0100883 free(module);
884}
Radek Krejci38d85362019-09-05 16:26:38 +0200885API void
886lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts)
887{
888 for (unsigned int u = 0; substmts[u].stmt; ++u) {
889 if (!substmts[u].storage) {
890 continue;
891 }
892
893 switch(substmts[u].stmt) {
894 case LY_STMT_TYPE:
895 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
896 /* single item */
897 struct lysc_type *type = *((struct lysc_type**)substmts[u].storage);
898 if (!type) {
899 break;
900 }
901 lysc_type_free(ctx, type);
902 } else {
903 /* multiple items */
904 struct lysc_type **types = *((struct lysc_type***)substmts[u].storage);
905 if (!types) {
906 break;
907 }
908 FREE_ARRAY(ctx, types, lysc_type2_free);
909 }
910 break;
911 case LY_STMT_UNITS:
912 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
913 /* single item */
914 const char *str = *((const char**)substmts[u].storage);
915 if (!str) {
916 break;
917 }
918 FREE_STRING(ctx, str);
919 } else {
920 /* multiple items */
921 const char **strs = *((const char***)substmts[u].storage);
922 if (!strs) {
923 break;
924 }
925 FREE_STRINGS(ctx, strs);
926 }
927 break;
928 case LY_STMT_STATUS:
Radek Krejciad5963b2019-09-06 16:03:05 +0200929 case LY_STMT_CONFIG:
Radek Krejci38d85362019-09-05 16:26:38 +0200930 /* nothing to do */
931 break;
932 case LY_STMT_IF_FEATURE: {
933 struct lysc_iffeature *iff = *((struct lysc_iffeature**)substmts[u].storage);
934 if (!iff) {
935 break;
936 }
937 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
938 /* single item */
939 lysc_iffeature_free(ctx, iff);
940 free(iff);
941 } else {
942 /* multiple items */
943 FREE_ARRAY(ctx, iff, lysc_iffeature_free);
944 }
945 break;
946 }
947
948 /* TODO other statements */
949 default:
950 LOGINT(ctx);
951 }
952 }
953}
David Sedlákebd3acf2019-07-26 15:04:32 +0200954
955void
Michal Vaskob36053d2020-03-26 15:49:30 +0100956yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx)
David Sedlákebd3acf2019-07-26 15:04:32 +0200957{
958 if (ctx) {
959 free(ctx);
960 }
961}
962
963void
Michal Vaskob36053d2020-03-26 15:49:30 +0100964yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx)
David Sedlákebd3acf2019-07-26 15:04:32 +0200965{
966 if (ctx) {
Michal Vaskob36053d2020-03-26 15:49:30 +0100967 lyxml_ctx_free(ctx->xmlctx);
David Sedlákebd3acf2019-07-26 15:04:32 +0200968 free(ctx);
969 }
970}