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