public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Paquier <[email protected]>
To: [email protected]
Subject: pgsql: xml2: Fix more memory leaks with libxml2 and XPath evaluations
Date: Tue, 02 Jun 2026 23:23:25 +0000
Message-ID: <[email protected]> (raw)

xml2: Fix more memory leaks with libxml2 and XPath evaluations

Several objects were allocated by libxml2 and never released in some
error or even success paths, leading to some memory leaks that would
stack across SQL calls:
- In pgxml_xpath(), the result of xmlXPathCompiledEval() could leak.
This now uses a TRY/CATCH block to ensure a correct cleanup of a
workspace on failure.
- In xpath_table() missed some objects not freed on failure.  Some
xmlFree() calls were missing for the results copied after a success.
- In pgxmlNodeSetToText(), xmlXPathCastNodeToString() allocates a result
that the caller is responsible for freeing.  It was not freed.

Most of the work of this commit stands on top of 732061150b0, that has
refactored xml2 to make the handling of such leaks easier.  The leaks
fixed here are more ancient than the commit mentioned above, and we have
never bothered doing something about them in older stable branches.

Author: Andrey Chernyy <[email protected]>
Co-authored-by: Michael Paquier <[email protected]>
Discussion: https://postgr.es/m/20260601010124.5edf9a20@andrnote

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/a77bdb11e6ba47f1a3e8363411b84c7f35f676e2

Modified Files
--------------
contrib/xml2/xpath.c | 109 ++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 87 insertions(+), 22 deletions(-)



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: pgsql: xml2: Fix more memory leaks with libxml2 and XPath evaluations
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox