diff -Naur a/tree.c b/tree.c
--- a/tree.c	2013-09-30 10:17:37.000000000 +0530
+++ b/tree.c	2013-09-30 10:38:34.000000000 +0530
@@ -4294,6 +4294,7 @@
 	    }
 	    if (doc->intSubset == NULL) {
 		q = (xmlNodePtr) xmlCopyDtd( (xmlDtdPtr) node );
+		if(q == NULL) return(q);
 		q->doc = doc;
 		q->parent = parent;
 		doc->intSubset = (xmlDtdPtr) q;
@@ -4305,6 +4306,7 @@
 	} else
 #endif /* LIBXML_TREE_ENABLED */
 	    q = xmlStaticCopyNode(node, doc, parent, 1);
+	if(q == NULL) return(q);
 	if (ret == NULL) {
 	    q->prev = NULL;
 	    ret = p = q;
