parser yang BUGFIX if-feature must be checked before unres type in leaf and leaflist
diff --git a/src/parser_yang.c b/src/parser_yang.c
index c043288..60f1fa8 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -3218,10 +3218,16 @@
         }
     } else if (stype->base == LY_TYPE_IDENT) {
         if (yang_check_identityref(module, &leaf->type, unres)) {
+            yang_type_free(module->ctx, &leaf->type);
             goto error;
         }
     }
 
+    if (yang_check_iffeatures(module, NULL, leaf, LEAF_KEYWORD, unres)) {
+        yang_type_free(module->ctx, &leaf->type);
+        goto error;
+    }
+
     if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, (struct lys_node *)leaf) == -1) {
         yang_type_free(module->ctx, &leaf->type);
         goto error;
@@ -3231,10 +3237,6 @@
         goto error;
     }
 
-    if (yang_check_iffeatures(module, NULL, leaf, LEAF_KEYWORD, unres)) {
-        goto error;
-    }
-
     /* check XPath dependencies */
     if ((leaf->when || leaf->must_size) && (unres_schema_add_node(module, unres, leaf, UNRES_XPATH, NULL) == -1)) {
         goto error;
@@ -3268,10 +3270,16 @@
         }
     } else if (stype->base == LY_TYPE_IDENT) {
         if (yang_check_identityref(module, &leaflist->type, unres)) {
+            yang_type_free(module->ctx, &leaflist->type);
             goto error;
         }
     }
 
+    if (yang_check_iffeatures(module, NULL, leaflist, LEAF_LIST_KEYWORD, unres)) {
+        yang_type_free(module->ctx, &leaflist->type);
+        goto error;
+    }
+
     if (unres_schema_add_node(module, unres, &leaflist->type, UNRES_TYPE_DER, (struct lys_node *)leaflist) == -1) {
         yang_type_free(module->ctx, &leaflist->type);
         goto error;
@@ -3296,10 +3304,6 @@
         }
     }
 
-    if (yang_check_iffeatures(module, NULL, leaflist, LEAF_LIST_KEYWORD, unres)) {
-        goto error;
-    }
-
     /* check XPath dependencies */
     if ((leaflist->when || leaflist->must_size) && (unres_schema_add_node(module, unres, leaflist, UNRES_XPATH, NULL) == -1)) {
         goto error;
@@ -3360,6 +3364,12 @@
 {
     char *value;
 
+    if (yang_check_iffeatures(module, NULL, choice, CHOICE_KEYWORD, unres)) {
+        free(choice->dflt);
+        choice->dflt = NULL;
+        goto error;
+    }
+
     if (choice->dflt) {
         value = (char *)choice->dflt;
         choice->dflt = NULL;
@@ -3370,10 +3380,6 @@
         free(value);
     }
 
-    if (yang_check_iffeatures(module, NULL, choice, CHOICE_KEYWORD, unres)) {
-        goto error;
-    }
-
     /* check XPath dependencies */
     if ((choice->when) && (unres_schema_add_node(module, unres, choice, UNRES_XPATH, NULL) == -1)) {
         goto error;
@@ -3440,11 +3446,12 @@
     child = augment->child;
     augment->child = NULL;
 
-    if (yang_check_nodes(module, (struct lys_node *)augment, child, config_opt, unres)) {
+    if (yang_check_iffeatures(module, NULL, augment, AUGMENT_KEYWORD, unres)) {
+        yang_free_nodes(module->ctx, child);
         goto error;
     }
 
-    if (yang_check_iffeatures(module, NULL, augment, AUGMENT_KEYWORD, unres)) {
+    if (yang_check_nodes(module, (struct lys_node *)augment, child, config_opt, unres)) {
         goto error;
     }