]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Remove xmlCleanupParser calls from contrib/xml2.
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 1 Mar 2010 05:17:01 +0000 (05:17 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 1 Mar 2010 05:17:01 +0000 (05:17 +0000)
These are unnecessary and probably dangerous.  I don't see any immediate
risk situations in the core XML support or contrib/xml2 itself, but there
could be issues with external uses of libxml2, and in any case it's an
accident waiting to happen.

contrib/xml2/xpath.c
contrib/xml2/xslt_proc.c

index 61cb27cf086fa844bba7f855bbcab71da60268f5..2bdc2b40d39640758275f459591a732bbb8e4f59 100644 (file)
@@ -139,12 +139,8 @@ xml_valid(PG_FUNCTION_ARGS)
 
        doctree = xmlParseMemory((char *) VARDATA(t), docsize);
        if (doctree == NULL)
-       {
-               xmlCleanupParser();
                PG_RETURN_BOOL(false);  /* i.e. not well-formed */
-       }
        xmlFreeDoc(doctree);
-       xmlCleanupParser();
        PG_RETURN_BOOL(true);
 }
 
@@ -302,7 +298,6 @@ xpath_nodeset(PG_FUNCTION_ARGS)
        xpres = pgxml_result_to_text(pgxml_xpath(PG_GETARG_TEXT_P(0), xpath),
                                                                 toptag, septag, NULL);
 
-       /* xmlCleanupParser(); done by result_to_text routine */
        pfree(xpath);
 
        if (xpres == NULL)
@@ -337,7 +332,6 @@ xpath_list(PG_FUNCTION_ARGS)
        xpres = pgxml_result_to_text(pgxml_xpath(PG_GETARG_TEXT_P(0), xpath),
                                                                 NULL, NULL, plainsep);
 
-       /* xmlCleanupParser(); done by result_to_text routine */
        pfree(xpath);
 
        if (xpres == NULL)
@@ -376,7 +370,6 @@ xpath_string(PG_FUNCTION_ARGS)
        xpres = pgxml_result_to_text(pgxml_xpath(PG_GETARG_TEXT_P(0), xpath),
                                                                 NULL, NULL, NULL);
 
-       xmlCleanupParser();
        pfree(xpath);
 
        if (xpres == NULL)
@@ -408,13 +401,10 @@ xpath_number(PG_FUNCTION_ARGS)
        pfree(xpath);
 
        if (res == NULL)
-       {
-               xmlCleanupParser();
                PG_RETURN_NULL();
-       }
 
        fRes = xmlXPathCastToNumber(res);
-       xmlCleanupParser();
+
        if (xmlXPathIsNaN(fRes))
                PG_RETURN_NULL();
 
@@ -445,13 +435,10 @@ xpath_bool(PG_FUNCTION_ARGS)
        pfree(xpath);
 
        if (res == NULL)
-       {
-               xmlCleanupParser();
                PG_RETURN_BOOL(false);
-       }
 
        bRes = xmlXPathCastToBoolean(res);
-       xmlCleanupParser();
+
        PG_RETURN_BOOL(bRes);
 }
 
@@ -474,9 +461,7 @@ pgxml_xpath(text *document, xmlChar *xpath)
 
        doctree = xmlParseMemory((char *) VARDATA(document), docsize);
        if (doctree == NULL)
-       {                                                       /* not well-formed */
-               return NULL;
-       }
+               return NULL;                    /* not well-formed */
 
        ctxt = xmlXPathNewContext(doctree);
        ctxt->node = xmlDocGetRootElement(doctree);
@@ -485,7 +470,6 @@ pgxml_xpath(text *document, xmlChar *xpath)
        comppath = xmlXPathCompile(xpath);
        if (comppath == NULL)
        {
-               xmlCleanupParser();
                xmlFreeDoc(doctree);
                elog_error("XPath Syntax Error", true);
        }
@@ -497,7 +481,6 @@ pgxml_xpath(text *document, xmlChar *xpath)
        if (res == NULL)
        {
                xmlXPathFreeContext(ctxt);
-               /* xmlCleanupParser(); */
                xmlFreeDoc(doctree);
 
                return NULL;
@@ -517,10 +500,8 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
        text       *xpres;
 
        if (res == NULL)
-       {
-               xmlCleanupParser();
                return NULL;
-       }
+
        switch (res->type)
        {
                case XPATH_NODESET:
@@ -545,9 +526,6 @@ pgxml_result_to_text(xmlXPathObjectPtr res,
        VARATT_SIZEP(xpres) = ressize + VARHDRSZ;
 
        /* Free various storage */
-       xmlCleanupParser();
-       /* xmlFreeDoc(doctree);  -- will die at end of tuple anyway */
-
        xmlFree(xpresstr);
 
        elog_error("XPath error", false);
@@ -786,7 +764,6 @@ xpath_table(PG_FUNCTION_ARGS)
                                        comppath = xmlXPathCompile(xpaths[j]);
                                        if (comppath == NULL)
                                        {
-                                               xmlCleanupParser();
                                                xmlFreeDoc(doctree);
                                                elog_error("XPath Syntax Error", true);
                                        }
@@ -851,8 +828,6 @@ xpath_table(PG_FUNCTION_ARGS)
                        pfree(xmldoc);
        }
 
-       xmlCleanupParser();
-
        tuplestore_donestoring(tupstore);
 
        SPI_finish();
index 51461695d811d11bd36fb1e36b68215997a875db..7fb3b294ee0765e8a664e09467f08240ac214956 100644 (file)
@@ -80,7 +80,6 @@ xslt_process(PG_FUNCTION_ARGS)
 
        if (doctree == NULL)
        {
-               xmlCleanupParser();
                elog_error("Error parsing XML document", false);
 
                PG_RETURN_NULL();
@@ -94,7 +93,6 @@ xslt_process(PG_FUNCTION_ARGS)
                if (ssdoc == NULL)
                {
                        xmlFreeDoc(doctree);
-                       xmlCleanupParser();
                        elog_error("Error parsing stylesheet as XML document", false);
                        PG_RETURN_NULL();
                }
@@ -109,7 +107,6 @@ xslt_process(PG_FUNCTION_ARGS)
        {
                xmlFreeDoc(doctree);
                xsltCleanupGlobals();
-               xmlCleanupParser();
                elog_error("Failed to parse stylesheet", false);
                PG_RETURN_NULL();
        }
@@ -122,7 +119,6 @@ xslt_process(PG_FUNCTION_ARGS)
        xmlFreeDoc(doctree);
 
        xsltCleanupGlobals();
-       xmlCleanupParser();
 
        if (resstat < 0)
                PG_RETURN_NULL();