parser: Fix memory leak in xmlCtxtSetSaxHandler
diff --git a/parserInternals.c b/parserInternals.c
index c3eec13..24e7c5b 100644
--- a/parserInternals.c
+++ b/parserInternals.c
@@ -3189,17 +3189,10 @@
  */
 int
 xmlCtxtSetSaxHandler(xmlParserCtxt *ctxt, const xmlSAXHandler *sax) {
-    xmlSAXHandler *copy;
-
-    if ((ctxt == NULL) || (sax == NULL))
+    if ((ctxt == NULL) || (ctxt->sax == NULL) || (sax == NULL))
         return(-1);
 
-    copy = xmlMalloc(sizeof(*copy));
-    if (copy == NULL)
-        return(-1);
-
-    memcpy(copy, sax, sizeof(*copy));
-    ctxt->sax = copy;
+    *ctxt->sax = *sax;
 
     return(0);
 }
diff --git a/testparser.c b/testparser.c
index 30b4eaa..02f5c5f 100644
--- a/testparser.c
+++ b/testparser.c
@@ -279,7 +279,7 @@
                        const xmlChar *systemId ATTRIBUTE_UNUSED) {
     xmlParserCtxtPtr ctxt = vctxt;
 
-    ctxt->myDoc->extSubset = ctxt->_private;
+    ctxt->myDoc->extSubset = xmlCtxtGetPrivate(ctxt);
 }
 
 static int
@@ -291,6 +291,7 @@
         "<doc>&test;</doc>\n";
     xmlParserInputBufferPtr input;
     xmlParserCtxtPtr ctxt;
+    xmlSAXHandler sax;
     xmlDtdPtr dtd;
     xmlDocPtr doc;
     xmlEntityPtr ent;
@@ -302,8 +303,10 @@
     dtd = xmlIOParseDTD(NULL, input, XML_CHAR_ENCODING_NONE);
 
     ctxt = xmlNewParserCtxt();
-    ctxt->_private = dtd;
-    ctxt->sax->externalSubset = testSwitchDtdExtSubset;
+    xmlCtxtSetPrivate(ctxt, dtd);
+    xmlSAXVersion(&sax, 2);
+    sax.externalSubset = testSwitchDtdExtSubset;
+    xmlCtxtSetSaxHandler(ctxt, &sax);
     doc = xmlCtxtReadMemory(ctxt, docContent, sizeof(docContent) - 1, NULL,
                             NULL, XML_PARSE_NOENT | XML_PARSE_DTDLOAD);
     xmlFreeParserCtxt(ctxt);