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.
diff --git a/src/tree_schema_free.c b/src/tree_schema_free.c
index c2aa78c..232d66f 100644
--- a/src/tree_schema_free.c
+++ b/src/tree_schema_free.c
@@ -597,6 +597,14 @@
     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 @@
         /* 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);
 }