applied patch from Alfred Mickautsch for better DTD support. fixed bug

* xmlwriter.c include/libxml/xmlwriter.h doc/* : applied patch from
  Alfred Mickautsch for better DTD support.
* SAX2.c HTMLparser.c parser.c xinclude.c xmllint.c xmlreader.c
  xmlschemas.c: fixed bug #137867 i.e. fixed properly the way
  reference counting is handled in the XML parser which had the
  side effect of removing a lot of hazardous cruft added to try
  to fix the problems associated as they popped up.
* xmlIO.c: FILE * close fixup for stderr/stdout
Daniel
diff --git a/xmlreader.c b/xmlreader.c
index 8a533a2..e1c2ef8 100644
--- a/xmlreader.c
+++ b/xmlreader.c
@@ -496,6 +496,7 @@
     if (cur->encoding != NULL) xmlFree((char *) cur->encoding);
     if (cur->oldNs != NULL) xmlFreeNsList(cur->oldNs);
     if (cur->URL != NULL) xmlFree((char *) cur->URL);
+    if (cur->dict != NULL) xmlDictFree(cur->dict);
     xmlFree(cur);
 }
 
@@ -3649,9 +3650,6 @@
 	return(NULL);
     
     reader->preserve = 1;
-    if ((reader->ctxt->myDoc->dict != NULL) &&
-	(reader->ctxt->myDoc->dict == reader->ctxt->dict))
-	xmlDictReference(reader->ctxt->dict);
     return(reader->ctxt->myDoc);
 }
 
@@ -4178,8 +4176,6 @@
 	    xmlParserInputBufferPtr buf;
 	    xmlCharEncoding enc = XML_CHAR_ENCODING_NONE;
 
-	    if (reader->ctxt->myDoc != NULL)
-	        xmlDictReference(reader->ctxt->myDoc->dict);
 	    xmlCtxtReset(reader->ctxt);
 	    buf = xmlAllocParserInputBuffer(enc);
 	    if (buf == NULL) return(-1);