schema BUGFIX freeing compiled type structure
Fix the order of the freeing due to necessary access of one of the
components when freeing the default values of the type.
@@ -597,6 +597,14 @@ lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type)
if (--type->refcount) {
return;
}
+ FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
+ if (type->dflt) {
+ type->plugin->free(ctx, type->dflt);
+ lysc_type_free(ctx, type->dflt->realtype);
+ free(type->dflt);
+ type->dflt = NULL;
+ }
+
switch(type->basetype) {
case LY_TYPE_BINARY:
FREE_MEMBER(ctx, ((struct lysc_type_bin*)type)->length, lysc_range_free);
@@ -640,12 +648,6 @@ lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type)
/* nothing to do */
break;
}
- FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
- if (type->dflt) {
- type->plugin->free(ctx, type->dflt);
- lysc_type_free(ctx, type->dflt->realtype);
- free(type->dflt);
- }
free(type);
}
