Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 2 | * @file tree_schema_free.c |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 4 | * @brief Freeing functions for schema tree structures. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 5 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 6 | * Copyright (c) 2019 CESNET, z.s.p.o. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 15 | #include <stdlib.h> |
| 16 | |
Michal Vasko | c5a2283 | 2020-08-20 13:21:33 +0200 | [diff] [blame] | 17 | #include "compat.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 18 | #include "common.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 19 | #include "plugins_exts.h" |
| 20 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 21 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 22 | #include "tree_data.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 24 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 25 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 26 | #include "xpath.h" |
| 27 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 28 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 29 | void lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 30 | |
| 31 | static void |
| 32 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 33 | { |
| 34 | struct lysp_stmt *child, *next; |
| 35 | |
| 36 | FREE_STRING(ctx, stmt->stmt); |
| 37 | FREE_STRING(ctx, stmt->arg); |
| 38 | |
| 39 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 40 | lysp_stmt_free(ctx, child); |
| 41 | } |
| 42 | |
| 43 | free(stmt); |
| 44 | } |
| 45 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 46 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 47 | lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext) |
| 48 | { |
| 49 | struct lysp_stmt *stmt, *next; |
| 50 | |
| 51 | FREE_STRING(ctx, ext->name); |
| 52 | FREE_STRING(ctx, ext->argument); |
| 53 | |
| 54 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
| 55 | lysp_stmt_free(ctx, stmt); |
| 56 | } |
| 57 | } |
| 58 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 59 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 60 | lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import) |
| 61 | { |
| 62 | /* imported module is freed directly from the context's list */ |
| 63 | FREE_STRING(ctx, import->name); |
| 64 | FREE_STRING(ctx, import->prefix); |
| 65 | FREE_STRING(ctx, import->dsc); |
| 66 | FREE_STRING(ctx, import->ref); |
| 67 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 68 | } |
| 69 | |
David Sedlák | 0c2bab9 | 2019-07-22 15:33:19 +0200 | [diff] [blame] | 70 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 71 | lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include) |
| 72 | { |
| 73 | if (include->submodule) { |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 74 | lysp_submodule_free(ctx, include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 75 | } |
| 76 | FREE_STRING(ctx, include->name); |
| 77 | FREE_STRING(ctx, include->dsc); |
| 78 | FREE_STRING(ctx, include->ref); |
| 79 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 80 | } |
| 81 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 82 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 83 | lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev) |
| 84 | { |
| 85 | FREE_STRING(ctx, rev->dsc); |
| 86 | FREE_STRING(ctx, rev->ref); |
| 87 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 88 | } |
| 89 | |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 90 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 91 | lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext) |
| 92 | { |
| 93 | FREE_STRING(ctx, ext->name); |
| 94 | FREE_STRING(ctx, ext->argument); |
| 95 | FREE_STRING(ctx, ext->dsc); |
| 96 | FREE_STRING(ctx, ext->ref); |
| 97 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 98 | if (ext->compiled) { |
| 99 | lysc_extension_free(ctx, &ext->compiled); |
| 100 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 101 | } |
| 102 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 103 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 104 | lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat) |
| 105 | { |
| 106 | FREE_STRING(ctx, feat->name); |
| 107 | FREE_STRINGS(ctx, feat->iffeatures); |
| 108 | FREE_STRING(ctx, feat->dsc); |
| 109 | FREE_STRING(ctx, feat->ref); |
| 110 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 111 | } |
| 112 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 113 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 114 | lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident) |
| 115 | { |
| 116 | FREE_STRING(ctx, ident->name); |
| 117 | FREE_STRINGS(ctx, ident->iffeatures); |
| 118 | FREE_STRINGS(ctx, ident->bases); |
| 119 | FREE_STRING(ctx, ident->dsc); |
| 120 | FREE_STRING(ctx, ident->ref); |
| 121 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 122 | } |
| 123 | |
| 124 | static void |
| 125 | lysp_restr_free(struct ly_ctx *ctx, struct lysp_restr *restr) |
| 126 | { |
| 127 | FREE_STRING(ctx, restr->arg); |
| 128 | FREE_STRING(ctx, restr->emsg); |
| 129 | FREE_STRING(ctx, restr->eapptag); |
| 130 | FREE_STRING(ctx, restr->dsc); |
| 131 | FREE_STRING(ctx, restr->ref); |
| 132 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 133 | } |
| 134 | |
| 135 | static void |
| 136 | lysp_type_enum_free(struct ly_ctx *ctx, struct lysp_type_enum *item) |
| 137 | { |
| 138 | FREE_STRING(ctx, item->name); |
| 139 | FREE_STRING(ctx, item->dsc); |
| 140 | FREE_STRING(ctx, item->ref); |
| 141 | FREE_STRINGS(ctx, item->iffeatures); |
| 142 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 143 | } |
| 144 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 145 | void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 146 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 147 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 148 | lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type) |
| 149 | { |
| 150 | FREE_STRING(ctx, type->name); |
| 151 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 152 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 153 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 154 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 155 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 156 | lyxp_expr_free(ctx, type->path); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 157 | FREE_STRINGS(ctx, type->bases); |
| 158 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 159 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 160 | if (type->compiled) { |
| 161 | lysc_type_free(ctx, type->compiled); |
| 162 | } |
| 163 | } |
| 164 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 165 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 166 | lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf) |
| 167 | { |
| 168 | FREE_STRING(ctx, tpdf->name); |
| 169 | FREE_STRING(ctx, tpdf->units); |
| 170 | FREE_STRING(ctx, tpdf->dflt); |
| 171 | FREE_STRING(ctx, tpdf->dsc); |
| 172 | FREE_STRING(ctx, tpdf->ref); |
| 173 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 174 | |
| 175 | lysp_type_free(ctx, &tpdf->type); |
| 176 | |
| 177 | } |
| 178 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 179 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 180 | lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout) |
| 181 | { |
| 182 | struct lysp_node *node, *next; |
| 183 | |
| 184 | FREE_ARRAY(ctx, inout->musts, lysp_restr_free); |
| 185 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 186 | FREE_ARRAY(ctx, inout->groupings, lysp_grp_free); |
| 187 | LY_LIST_FOR_SAFE(inout->data, next, node) { |
| 188 | lysp_node_free(ctx, node); |
| 189 | } |
| 190 | FREE_ARRAY(ctx, inout->exts, lysp_ext_instance_free); |
| 191 | |
| 192 | } |
| 193 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 194 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 195 | lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action) |
| 196 | { |
| 197 | FREE_STRING(ctx, action->name); |
| 198 | FREE_STRING(ctx, action->dsc); |
| 199 | FREE_STRING(ctx, action->ref); |
| 200 | FREE_STRINGS(ctx, action->iffeatures); |
| 201 | FREE_ARRAY(ctx, action->typedefs, lysp_tpdf_free); |
| 202 | FREE_ARRAY(ctx, action->groupings, lysp_grp_free); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 203 | lysp_action_inout_free(ctx, &action->input); |
| 204 | lysp_action_inout_free(ctx, &action->output); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 205 | FREE_ARRAY(ctx, action->exts, lysp_ext_instance_free); |
| 206 | } |
| 207 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 208 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 209 | lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif) |
| 210 | { |
| 211 | struct lysp_node *node, *next; |
| 212 | |
| 213 | FREE_STRING(ctx, notif->name); |
| 214 | FREE_STRING(ctx, notif->dsc); |
| 215 | FREE_STRING(ctx, notif->ref); |
| 216 | FREE_STRINGS(ctx, notif->iffeatures); |
| 217 | FREE_ARRAY(ctx, notif->musts, lysp_restr_free); |
| 218 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 219 | FREE_ARRAY(ctx, notif->groupings, lysp_grp_free); |
| 220 | LY_LIST_FOR_SAFE(notif->data, next, node) { |
| 221 | lysp_node_free(ctx, node); |
| 222 | } |
| 223 | FREE_ARRAY(ctx, notif->exts, lysp_ext_instance_free); |
| 224 | } |
| 225 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 226 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 227 | lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp) |
| 228 | { |
| 229 | struct lysp_node *node, *next; |
| 230 | |
| 231 | FREE_STRING(ctx, grp->name); |
| 232 | FREE_STRING(ctx, grp->dsc); |
| 233 | FREE_STRING(ctx, grp->ref); |
| 234 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
| 235 | FREE_ARRAY(ctx, grp->groupings, lysp_grp_free); |
| 236 | LY_LIST_FOR_SAFE(grp->data, next, node) { |
| 237 | lysp_node_free(ctx, node); |
| 238 | } |
| 239 | FREE_ARRAY(ctx, grp->actions, lysp_action_free); |
| 240 | FREE_ARRAY(ctx, grp->notifs, lysp_notif_free); |
| 241 | FREE_ARRAY(ctx, grp->exts, lysp_ext_instance_free); |
| 242 | } |
| 243 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 244 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 245 | lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when) |
| 246 | { |
| 247 | FREE_STRING(ctx, when->cond); |
| 248 | FREE_STRING(ctx, when->dsc); |
| 249 | FREE_STRING(ctx, when->ref); |
| 250 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 251 | } |
| 252 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 253 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 254 | lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment) |
| 255 | { |
| 256 | struct lysp_node *node, *next; |
| 257 | |
| 258 | FREE_STRING(ctx, augment->nodeid); |
| 259 | FREE_STRING(ctx, augment->dsc); |
| 260 | FREE_STRING(ctx, augment->ref); |
| 261 | FREE_MEMBER(ctx, augment->when, lysp_when_free); |
| 262 | FREE_STRINGS(ctx, augment->iffeatures); |
| 263 | LY_LIST_FOR_SAFE(augment->child, next, node) { |
| 264 | lysp_node_free(ctx, node); |
| 265 | } |
| 266 | FREE_ARRAY(ctx, augment->actions, lysp_action_free); |
| 267 | FREE_ARRAY(ctx, augment->notifs, lysp_notif_free); |
| 268 | FREE_ARRAY(ctx, augment->exts, lysp_ext_instance_free); |
| 269 | } |
| 270 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 271 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 272 | lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d) |
| 273 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 274 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 275 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 276 | |
| 277 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 278 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 279 | case LYS_DEV_NOT_SUPPORTED: |
| 280 | /* nothing to do */ |
| 281 | break; |
| 282 | case LYS_DEV_ADD: |
| 283 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
| 284 | FREE_STRING(ctx, add->units); |
| 285 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
| 286 | FREE_STRINGS(ctx, add->uniques); |
| 287 | FREE_STRINGS(ctx, add->dflts); |
| 288 | break; |
| 289 | case LYS_DEV_REPLACE: |
| 290 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
| 291 | FREE_STRING(ctx, rpl->units); |
| 292 | FREE_STRING(ctx, rpl->dflt); |
| 293 | break; |
| 294 | default: |
| 295 | LOGINT(ctx); |
| 296 | break; |
| 297 | } |
| 298 | } |
| 299 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 300 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 301 | lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev) |
| 302 | { |
| 303 | struct lysp_deviate *next, *iter; |
| 304 | |
| 305 | FREE_STRING(ctx, dev->nodeid); |
| 306 | FREE_STRING(ctx, dev->dsc); |
| 307 | FREE_STRING(ctx, dev->ref); |
| 308 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 309 | lysp_deviate_free(ctx, iter); |
| 310 | free(iter); |
| 311 | } |
| 312 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 313 | } |
| 314 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 315 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 316 | lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref) |
| 317 | { |
| 318 | FREE_STRING(ctx, ref->nodeid); |
| 319 | FREE_STRING(ctx, ref->dsc); |
| 320 | FREE_STRING(ctx, ref->ref); |
| 321 | FREE_STRINGS(ctx, ref->iffeatures); |
| 322 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
| 323 | FREE_STRING(ctx, ref->presence); |
| 324 | FREE_STRINGS(ctx, ref->dflts); |
| 325 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 326 | } |
| 327 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 328 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 329 | lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node) |
| 330 | { |
| 331 | struct lysp_node *child, *next; |
| 332 | |
| 333 | FREE_STRING(ctx, node->name); |
| 334 | FREE_STRING(ctx, node->dsc); |
| 335 | FREE_STRING(ctx, node->ref); |
| 336 | FREE_MEMBER(ctx, node->when, lysp_when_free); |
| 337 | FREE_STRINGS(ctx, node->iffeatures); |
| 338 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 339 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 340 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 341 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 342 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->musts, lysp_restr_free); |
| 343 | FREE_STRING(ctx, ((struct lysp_node_container *)node)->presence); |
| 344 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->typedefs, lysp_tpdf_free); |
| 345 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->groupings, lysp_grp_free); |
| 346 | LY_LIST_FOR_SAFE(((struct lysp_node_container *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 347 | lysp_node_free(ctx, child); |
| 348 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 349 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->actions, lysp_action_free); |
| 350 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->notifs, lysp_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 351 | break; |
| 352 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 353 | FREE_ARRAY(ctx, ((struct lysp_node_leaf *)node)->musts, lysp_restr_free); |
| 354 | lysp_type_free(ctx, &((struct lysp_node_leaf *)node)->type); |
| 355 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->units); |
| 356 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 357 | break; |
| 358 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 359 | FREE_ARRAY(ctx, ((struct lysp_node_leaflist *)node)->musts, lysp_restr_free); |
| 360 | lysp_type_free(ctx, &((struct lysp_node_leaflist *)node)->type); |
| 361 | FREE_STRING(ctx, ((struct lysp_node_leaflist *)node)->units); |
| 362 | FREE_STRINGS(ctx, ((struct lysp_node_leaflist *)node)->dflts); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 363 | break; |
| 364 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 365 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->musts, lysp_restr_free); |
| 366 | FREE_STRING(ctx, ((struct lysp_node_list *)node)->key); |
| 367 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->typedefs, lysp_tpdf_free); |
| 368 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->groupings, lysp_grp_free); |
| 369 | LY_LIST_FOR_SAFE(((struct lysp_node_list *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 370 | lysp_node_free(ctx, child); |
| 371 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 372 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->actions, lysp_action_free); |
| 373 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->notifs, lysp_notif_free); |
| 374 | FREE_STRINGS(ctx, ((struct lysp_node_list *)node)->uniques); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 375 | break; |
| 376 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 377 | LY_LIST_FOR_SAFE(((struct lysp_node_choice *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 378 | lysp_node_free(ctx, child); |
| 379 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 380 | FREE_STRING(ctx, ((struct lysp_node_choice *)node)->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 381 | break; |
| 382 | case LYS_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 383 | LY_LIST_FOR_SAFE(((struct lysp_node_case *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 384 | lysp_node_free(ctx, child); |
| 385 | } |
| 386 | break; |
| 387 | case LYS_ANYDATA: |
| 388 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 389 | FREE_ARRAY(ctx, ((struct lysp_node_anydata *)node)->musts, lysp_restr_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 390 | break; |
| 391 | case LYS_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 392 | FREE_ARRAY(ctx, ((struct lysp_node_uses *)node)->refines, lysp_refine_free); |
| 393 | FREE_ARRAY(ctx, ((struct lysp_node_uses *)node)->augments, lysp_augment_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 394 | break; |
| 395 | default: |
| 396 | LOGINT(ctx); |
| 397 | } |
| 398 | |
| 399 | free(node); |
| 400 | } |
| 401 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 402 | void |
| 403 | lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod) |
| 404 | { |
| 405 | struct lysp_node *node, *next; |
| 406 | |
Radek Krejci | 40544fa | 2019-01-11 09:38:37 +0100 | [diff] [blame] | 407 | if (!submod) { |
| 408 | return; |
| 409 | } |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 410 | |
| 411 | FREE_ARRAY(ctx, submod->imports, lysp_import_free); |
| 412 | FREE_ARRAY(ctx, submod->includes, lysp_include_free); |
| 413 | |
| 414 | FREE_ARRAY(ctx, submod->revs, lysp_revision_free); |
| 415 | FREE_ARRAY(ctx, submod->extensions, lysp_ext_free); |
| 416 | FREE_ARRAY(ctx, submod->features, lysp_feature_free); |
| 417 | FREE_ARRAY(ctx, submod->identities, lysp_ident_free); |
| 418 | FREE_ARRAY(ctx, submod->typedefs, lysp_tpdf_free); |
| 419 | FREE_ARRAY(ctx, submod->groupings, lysp_grp_free); |
| 420 | LY_LIST_FOR_SAFE(submod->data, next, node) { |
| 421 | lysp_node_free(ctx, node); |
| 422 | } |
| 423 | FREE_ARRAY(ctx, submod->augments, lysp_augment_free); |
| 424 | FREE_ARRAY(ctx, submod->rpcs, lysp_action_free); |
| 425 | FREE_ARRAY(ctx, submod->notifs, lysp_notif_free); |
| 426 | FREE_ARRAY(ctx, submod->deviations, lysp_deviation_free); |
| 427 | FREE_ARRAY(ctx, submod->exts, lysp_ext_instance_free); |
| 428 | |
| 429 | FREE_STRING(ctx, submod->belongsto); |
| 430 | FREE_STRING(ctx, submod->name); |
| 431 | FREE_STRING(ctx, submod->filepath); |
| 432 | FREE_STRING(ctx, submod->prefix); |
| 433 | FREE_STRING(ctx, submod->org); |
| 434 | FREE_STRING(ctx, submod->contact); |
| 435 | FREE_STRING(ctx, submod->dsc); |
| 436 | FREE_STRING(ctx, submod->ref); |
| 437 | |
| 438 | free(submod); |
| 439 | } |
| 440 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 441 | API void |
| 442 | lysp_module_free(struct lysp_module *module) |
| 443 | { |
| 444 | struct ly_ctx *ctx; |
| 445 | struct lysp_node *node, *next; |
| 446 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 447 | if (!module) { |
| 448 | return; |
| 449 | } |
| 450 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 451 | |
| 452 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
| 453 | FREE_ARRAY(ctx, module->includes, lysp_include_free); |
| 454 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 455 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 456 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 457 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 458 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 459 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
| 460 | FREE_ARRAY(ctx, module->groupings, lysp_grp_free); |
| 461 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 462 | lysp_node_free(ctx, node); |
| 463 | } |
| 464 | FREE_ARRAY(ctx, module->augments, lysp_augment_free); |
| 465 | FREE_ARRAY(ctx, module->rpcs, lysp_action_free); |
| 466 | FREE_ARRAY(ctx, module->notifs, lysp_notif_free); |
| 467 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 468 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 469 | |
| 470 | free(module); |
| 471 | } |
| 472 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 473 | void |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 474 | lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext) |
| 475 | { |
| 476 | if (--(*ext)->refcount) { |
| 477 | return; |
| 478 | } |
| 479 | FREE_STRING(ctx, (*ext)->name); |
| 480 | FREE_STRING(ctx, (*ext)->argument); |
| 481 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 482 | free(*ext); |
| 483 | } |
| 484 | |
| 485 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 486 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 487 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 488 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 489 | ext->def->plugin->free(ctx, ext); |
| 490 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 491 | if (ext->def) { |
| 492 | lysc_extension_free(ctx, &ext->def); |
| 493 | } |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 494 | FREE_STRING(ctx, ext->argument); |
| 495 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 496 | } |
| 497 | |
| 498 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 499 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 500 | { |
| 501 | LY_ARRAY_FREE(iff->features); |
| 502 | free(iff->expr); |
| 503 | } |
| 504 | |
| 505 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 506 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 507 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 508 | if (--(*w)->refcount) { |
| 509 | return; |
| 510 | } |
| 511 | lyxp_expr_free(ctx, (*w)->cond); |
| 512 | FREE_STRING(ctx, (*w)->dsc); |
| 513 | FREE_STRING(ctx, (*w)->ref); |
| 514 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 515 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 518 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 519 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 520 | { |
| 521 | lyxp_expr_free(ctx, must->cond); |
| 522 | FREE_STRING(ctx, must->emsg); |
| 523 | FREE_STRING(ctx, must->eapptag); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 524 | FREE_STRING(ctx, must->dsc); |
| 525 | FREE_STRING(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 526 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 527 | } |
| 528 | |
| 529 | static void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 530 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 531 | { |
| 532 | FREE_STRING(ctx, ident->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 533 | FREE_STRING(ctx, ident->dsc); |
| 534 | FREE_STRING(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 535 | FREE_ARRAY(ctx, ident->iffeatures, lysc_iffeature_free); |
| 536 | LY_ARRAY_FREE(ident->derived); |
| 537 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 538 | } |
| 539 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 540 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 541 | lysc_feature_free(struct ly_ctx *ctx, struct lysc_feature *feat) |
| 542 | { |
| 543 | FREE_STRING(ctx, feat->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 544 | FREE_STRING(ctx, feat->dsc); |
| 545 | FREE_STRING(ctx, feat->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 546 | FREE_ARRAY(ctx, feat->iffeatures, lysc_iffeature_free); |
| 547 | LY_ARRAY_FREE(feat->depfeatures); |
| 548 | FREE_ARRAY(ctx, feat->exts, lysc_ext_instance_free); |
| 549 | } |
| 550 | |
| 551 | static void |
| 552 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 553 | { |
| 554 | LY_ARRAY_FREE(range->parts); |
| 555 | FREE_STRING(ctx, range->eapptag); |
| 556 | FREE_STRING(ctx, range->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 557 | FREE_STRING(ctx, range->dsc); |
| 558 | FREE_STRING(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 559 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 560 | } |
| 561 | |
| 562 | static void |
| 563 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 564 | { |
| 565 | if (--(*pattern)->refcount) { |
| 566 | return; |
| 567 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 568 | pcre2_code_free((*pattern)->code); |
| 569 | FREE_STRING(ctx, (*pattern)->expr); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 570 | FREE_STRING(ctx, (*pattern)->eapptag); |
| 571 | FREE_STRING(ctx, (*pattern)->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 572 | FREE_STRING(ctx, (*pattern)->dsc); |
| 573 | FREE_STRING(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 574 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 575 | free(*pattern); |
| 576 | } |
| 577 | |
| 578 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 579 | lysc_enum_item_free(struct ly_ctx *ctx, struct lysc_type_bitenum_item *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 580 | { |
| 581 | FREE_STRING(ctx, item->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 582 | FREE_STRING(ctx, item->dsc); |
| 583 | FREE_STRING(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 584 | FREE_ARRAY(ctx, item->iffeatures, lysc_iffeature_free); |
| 585 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 586 | } |
| 587 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 588 | static void |
| 589 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 590 | { |
| 591 | lysc_type_free(ctx, *type); |
| 592 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 593 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 594 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 595 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 596 | { |
| 597 | if (--type->refcount) { |
| 598 | return; |
| 599 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 600 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 601 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 602 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 603 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 604 | break; |
| 605 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 606 | FREE_ARRAY(ctx, (struct lysc_type_bitenum_item *)((struct lysc_type_bits *)type)->bits, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 607 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 608 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 609 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 610 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 611 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 612 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 613 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 614 | break; |
| 615 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 616 | FREE_ARRAY(ctx, ((struct lysc_type_enum *)type)->enums, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 617 | break; |
| 618 | case LY_TYPE_INT8: |
| 619 | case LY_TYPE_UINT8: |
| 620 | case LY_TYPE_INT16: |
| 621 | case LY_TYPE_UINT16: |
| 622 | case LY_TYPE_INT32: |
| 623 | case LY_TYPE_UINT32: |
| 624 | case LY_TYPE_INT64: |
| 625 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 626 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 627 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 628 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 629 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 630 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 631 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 632 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 633 | break; |
| 634 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 635 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 636 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 637 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 638 | case LY_TYPE_BOOL: |
| 639 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 640 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 641 | /* nothing to do */ |
| 642 | break; |
| 643 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 644 | |
| 645 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 646 | free(type); |
| 647 | } |
| 648 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 649 | void |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 650 | lysc_action_inout_free(struct ly_ctx *ctx, struct lysc_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 651 | { |
| 652 | struct lysc_node *child, *child_next; |
| 653 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 654 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
| 655 | LY_LIST_FOR_SAFE(inout->data, child_next, child) { |
| 656 | lysc_node_free(ctx, child); |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | void |
| 661 | lysc_action_free(struct ly_ctx *ctx, struct lysc_action *action) |
| 662 | { |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 663 | FREE_STRING(ctx, action->name); |
| 664 | FREE_STRING(ctx, action->dsc); |
| 665 | FREE_STRING(ctx, action->ref); |
| 666 | FREE_ARRAY(ctx, action->iffeatures, lysc_iffeature_free); |
| 667 | FREE_ARRAY(ctx, action->exts, lysc_ext_instance_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 668 | FREE_ARRAY(ctx, action->input_exts, lysc_ext_instance_free); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 669 | lysc_action_inout_free(ctx, &action->input); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 670 | FREE_ARRAY(ctx, action->output_exts, lysc_ext_instance_free); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 671 | lysc_action_inout_free(ctx, &action->output); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 672 | } |
| 673 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 674 | void |
| 675 | lysc_notif_free(struct ly_ctx *ctx, struct lysc_notif *notif) |
| 676 | { |
| 677 | struct lysc_node *child, *child_next; |
| 678 | |
| 679 | FREE_STRING(ctx, notif->name); |
| 680 | FREE_STRING(ctx, notif->dsc); |
| 681 | FREE_STRING(ctx, notif->ref); |
| 682 | FREE_ARRAY(ctx, notif->iffeatures, lysc_iffeature_free); |
| 683 | FREE_ARRAY(ctx, notif->exts, lysc_ext_instance_free); |
| 684 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
| 685 | LY_LIST_FOR_SAFE(notif->data, child_next, child) { |
| 686 | lysc_node_free(ctx, child); |
| 687 | } |
| 688 | } |
| 689 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 690 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 691 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 692 | { |
| 693 | struct lysc_node *child, *child_next; |
| 694 | |
| 695 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
| 696 | lysc_node_free(ctx, child); |
| 697 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 698 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 699 | FREE_ARRAY(ctx, node->actions, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 700 | FREE_ARRAY(ctx, node->notifs, lysc_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | static void |
| 704 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 705 | { |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 706 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 707 | if (node->type) { |
| 708 | lysc_type_free(ctx, node->type); |
| 709 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 710 | FREE_STRING(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 711 | if (node->dflt) { |
| 712 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
| 713 | lysc_type_free(ctx, node->dflt->realtype); |
| 714 | free(node->dflt); |
| 715 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 718 | static void |
| 719 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 720 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 721 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 722 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 723 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 724 | if (node->type) { |
| 725 | lysc_type_free(ctx, node->type); |
| 726 | } |
| 727 | FREE_STRING(ctx, node->units); |
| 728 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 729 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
| 730 | lysc_type_free(ctx, node->dflts[u]->realtype); |
| 731 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 732 | } |
| 733 | LY_ARRAY_FREE(node->dflts); |
| 734 | } |
| 735 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 736 | static void |
| 737 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 738 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 739 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 740 | struct lysc_node *child, *child_next; |
| 741 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 742 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
| 743 | lysc_node_free(ctx, child); |
| 744 | } |
| 745 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 746 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 747 | LY_ARRAY_FOR(node->uniques, u) { |
| 748 | LY_ARRAY_FREE(node->uniques[u]); |
| 749 | } |
| 750 | LY_ARRAY_FREE(node->uniques); |
| 751 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 752 | FREE_ARRAY(ctx, node->actions, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 753 | FREE_ARRAY(ctx, node->notifs, lysc_notif_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 756 | static void |
| 757 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 758 | { |
| 759 | struct lysc_node *child, *child_next; |
| 760 | |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 761 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
| 762 | lysc_node_free(ctx, child); |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | static void |
| 767 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 768 | { |
| 769 | struct lysc_node *child, *child_next; |
| 770 | |
| 771 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
| 772 | lysc_node_free(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 773 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 774 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 775 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 776 | static void |
| 777 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 778 | { |
| 779 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 782 | void |
| 783 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node) |
| 784 | { |
| 785 | /* common part */ |
| 786 | FREE_STRING(ctx, node->name); |
Radek Krejci | 12fb914 | 2019-01-08 09:45:30 +0100 | [diff] [blame] | 787 | FREE_STRING(ctx, node->dsc); |
| 788 | FREE_STRING(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 789 | |
| 790 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 791 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 792 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 793 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 794 | break; |
| 795 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 796 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 797 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 798 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 799 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 800 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 801 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 802 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 803 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 804 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 805 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 806 | break; |
| 807 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 808 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 809 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 810 | case LYS_ANYDATA: |
| 811 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 812 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 813 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 814 | default: |
| 815 | LOGINT(ctx); |
| 816 | } |
| 817 | |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 818 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 819 | FREE_ARRAY(ctx, node->iffeatures, lysc_iffeature_free); |
| 820 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 821 | free(node); |
| 822 | } |
| 823 | |
| 824 | static void |
| 825 | lysc_module_free_(struct lysc_module *module) |
| 826 | { |
| 827 | struct ly_ctx *ctx; |
| 828 | struct lysc_node *node, *node_next; |
| 829 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 830 | LY_CHECK_ARG_RET(NULL, module, ); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 831 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 832 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 833 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
| 834 | lysc_node_free(ctx, node); |
| 835 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 836 | FREE_ARRAY(ctx, module->rpcs, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 837 | FREE_ARRAY(ctx, module->notifs, lysc_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 838 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
Michal Vasko | 57c10cd | 2020-05-27 15:57:11 +0200 | [diff] [blame] | 839 | LY_ARRAY_FREE(module->deviated_by); |
Michal Vasko | a3af598 | 2020-06-29 11:51:37 +0200 | [diff] [blame] | 840 | LY_ARRAY_FREE(module->augmented_by); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 841 | |
| 842 | free(module); |
| 843 | } |
| 844 | |
| 845 | void |
| 846 | lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 847 | { |
Radek Krejci | 9b04289 | 2019-02-13 14:28:44 +0100 | [diff] [blame] | 848 | /* TODO use the destructor, this just suppress warning about unused parameter */ |
| 849 | (void) private_destructor; |
| 850 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 851 | if (module) { |
| 852 | lysc_module_free_(module); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | void |
| 857 | lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 858 | { |
| 859 | if (!module) { |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | lysc_module_free(module->compiled, private_destructor); |
Radek Krejci | 14915cc | 2020-09-14 17:28:13 +0200 | [diff] [blame] | 864 | FREE_ARRAY(module->ctx, module->features, lysc_feature_free); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame^] | 865 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 866 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 867 | |
| 868 | FREE_STRING(module->ctx, module->name); |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 869 | FREE_STRING(module->ctx, module->revision); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 870 | FREE_STRING(module->ctx, module->ns); |
| 871 | FREE_STRING(module->ctx, module->prefix); |
| 872 | FREE_STRING(module->ctx, module->filepath); |
| 873 | FREE_STRING(module->ctx, module->org); |
| 874 | FREE_STRING(module->ctx, module->contact); |
| 875 | FREE_STRING(module->ctx, module->dsc); |
| 876 | FREE_STRING(module->ctx, module->ref); |
| 877 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 878 | free(module); |
| 879 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 880 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 881 | API void |
| 882 | lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
| 883 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 884 | for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 885 | if (!substmts[u].storage) { |
| 886 | continue; |
| 887 | } |
| 888 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 889 | switch (substmts[u].stmt) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 890 | case LY_STMT_TYPE: |
| 891 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 892 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 893 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 894 | if (!type) { |
| 895 | break; |
| 896 | } |
| 897 | lysc_type_free(ctx, type); |
| 898 | } else { |
| 899 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 900 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 901 | if (!types) { |
| 902 | break; |
| 903 | } |
| 904 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 905 | } |
| 906 | break; |
| 907 | case LY_STMT_UNITS: |
| 908 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 909 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 910 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 911 | if (!str) { |
| 912 | break; |
| 913 | } |
| 914 | FREE_STRING(ctx, str); |
| 915 | } else { |
| 916 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 917 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 918 | if (!strs) { |
| 919 | break; |
| 920 | } |
| 921 | FREE_STRINGS(ctx, strs); |
| 922 | } |
| 923 | break; |
| 924 | case LY_STMT_STATUS: |
Radek Krejci | ad5963b | 2019-09-06 16:03:05 +0200 | [diff] [blame] | 925 | case LY_STMT_CONFIG: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 926 | /* nothing to do */ |
| 927 | break; |
| 928 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 929 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 930 | if (!iff) { |
| 931 | break; |
| 932 | } |
| 933 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 934 | /* single item */ |
| 935 | lysc_iffeature_free(ctx, iff); |
| 936 | free(iff); |
| 937 | } else { |
| 938 | /* multiple items */ |
| 939 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 940 | } |
| 941 | break; |
| 942 | } |
| 943 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 944 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 945 | default: |
| 946 | LOGINT(ctx); |
| 947 | } |
| 948 | } |
| 949 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 950 | |
| 951 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 952 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 953 | { |
| 954 | if (ctx) { |
| 955 | free(ctx); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 960 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 961 | { |
| 962 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 963 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 964 | free(ctx); |
| 965 | } |
| 966 | } |