fixed problem reported on bug #460415 Daniel

* xmlsave.c: fixed problem reported on bug #460415
Daniel

svn path=/trunk/; revision=3646
diff --git a/xmlsave.c b/xmlsave.c
index b97327e..30ebf49 100644
--- a/xmlsave.c
+++ b/xmlsave.c
@@ -2187,12 +2187,13 @@
     encoding = (const char *) cur->encoding;
 
     if (encoding != NULL) {
-		handler = xmlFindCharEncodingHandler(encoding);
-	    if (handler == NULL) {
-		xmlFree((char *) cur->encoding);
-		cur->encoding = NULL;
-	    }
+	handler = xmlFindCharEncodingHandler(encoding);
+	if (handler == NULL) {
+	    xmlFree((char *) cur->encoding);
+	    cur->encoding = NULL;
+	    encoding = NULL;
 	}
+    }
     buf = xmlOutputBufferCreateFile(f, handler);
     if (buf == NULL) return(-1);
     memset(&ctxt, 0, sizeof(ctxt));