further fixes for out of memory condition, mostly from Olivier Andrieu.

* SAX2.c, tree.c, uri.c, xmlIO.c, xmlreader.c: further
  fixes for out of memory condition, mostly from Olivier
  Andrieu.
* testOOM.c: some further improvement by Olivier, with
  a further small enhancement for easier debugging.
diff --git a/tree.c b/tree.c
index fc22d52..a7109f9 100644
--- a/tree.c
+++ b/tree.c
@@ -6747,8 +6747,8 @@
 	if (rebuf != NULL) {
 	    memcpy(rebuf, buf->content, buf->use);
 	    xmlFree(buf->content);
+	    rebuf[buf->use] = 0;
 	}
-	rebuf[buf->use] = 0;
     }
     if (rebuf == NULL) {
 	xmlTreeErrMemory("growing buffer");