From 6ff5a77a921eb3fdaa25e4e7884d7c1ab17a63e3 Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Mon, 1 Jun 2026 12:59:05 +0900 Subject: [PATCH v2 3/3] xml2: Fix two more leaks - In pgxmlNodeSetToText(), the result could be leaked on error. - In pgxml_xpath(), a context could be compiled and would leak if the - call fails. --- contrib/xml2/xpath.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/contrib/xml2/xpath.c b/contrib/xml2/xpath.c index ac140a640e07..9fe75cb5ff40 100644 --- a/contrib/xml2/xpath.c +++ b/contrib/xml2/xpath.c @@ -223,6 +223,8 @@ pgxmlNodeSetToText(xmlNodeSetPtr nodeset, } PG_CATCH(); { + if (result) + xmlFree(result); if (str) xmlFree(str); if (buf) @@ -513,8 +515,12 @@ pgxml_xpath(text *document, xmlChar *xpath, PgXmlErrorContext *xmlerrcxt) /* compile the path */ comppath = xmlXPathCtxtCompile(workspace->ctxt, xpath); if (comppath == NULL || pg_xml_error_occurred(xmlerrcxt)) + { + if (comppath != NULL) + xmlXPathFreeCompExpr(comppath); xml_ereport(xmlerrcxt, ERROR, ERRCODE_INVALID_ARGUMENT_FOR_XQUERY, "XPath Syntax Error"); + } /* Now evaluate the path expression. */ workspace->res = xmlXPathCompiledEval(comppath, workspace->ctxt); -- 2.54.0