schema compile MAINTENANCE null dereference

Probably coverity false positive.
diff --git a/src/schema_compile.c b/src/schema_compile.c
index 088fbeb..3dcc175 100644
--- a/src/schema_compile.c
+++ b/src/schema_compile.c
@@ -586,16 +586,18 @@
             if (u < LY_ARRAY_COUNT(*idents)) {
                 memmove(&(*idents)[u], &(*idents)[u + 1], (LY_ARRAY_COUNT(*idents) - u) * sizeof **idents);
             }
-            if (!LY_ARRAY_COUNT(*idents)) {
-                LY_ARRAY_FREE(*idents);
-                *idents = NULL;
-            }
 
             /* revert compilation of all the previous identities */
             for (v = 0; v < u; ++v) {
                 LY_ARRAY_FREE((*idents)[v].derived);
             }
 
+            /* free the whole array if there are no identites left */
+            if (!LY_ARRAY_COUNT(*idents)) {
+                LY_ARRAY_FREE(*idents);
+                *idents = NULL;
+            }
+
             /* restart the whole process without this identity */
             goto restart;
         }