parsers BUGFIX invalid reads of freed memory

...when submodule parsing fails.
diff --git a/src/parser_yang.c b/src/parser_yang.c
index c9c1d5f..c646ee2 100644
--- a/src/parser_yang.c
+++ b/src/parser_yang.c
@@ -2741,8 +2741,6 @@
 
 error:
     /* cleanup */
-    unres_schema_free((struct lys_module *)submodule, &unres, 0);
-
     if (!submodule || !submodule->name) {
         free(submodule);
         LOGERR(ly_errno, "Submodule parsing failed.");
@@ -2751,6 +2749,7 @@
 
     LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name);
 
+    unres_schema_free((struct lys_module *)submodule, &unres, 0);
     lyp_check_circmod_pop(module->ctx);
     lys_sub_module_remove_devs_augs((struct lys_module *)submodule);
     lys_submodule_module_data_free(submodule);