diff --git a/relaxng.c b/relaxng.c
index f34dc14..16d8b46 100644
--- a/relaxng.c
+++ b/relaxng.c
@@ -9419,6 +9419,10 @@ xmlRelaxNGValidateInterleave(xmlRelaxNGValidCtxtPtr ctxt,
     oldstate = ctxt->state;
     for (i = 0; i < nbgroups; i++) {
         ctxt->state = xmlRelaxNGCopyValidState(ctxt, oldstate);
+	if (ctxt->state == NULL) {
+	    ret = -1;
+	    break;
+	}		
         group = partitions->groups[i];
         if (lasts[i] != NULL) {
             last = lasts[i]->next;
