postgresql/contrib/xml2
Michael Paquier a77bdb11e6 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 732061150b, 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 <andrey.cherny@tantorlabs.com>
Co-authored-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/20260601010124.5edf9a20@andrnote
2026-06-03 08:16:42 +09:00
..
expected xml2: Fix failure with xslt_process() under -fsanitize=undefined 2026-03-13 16:06:28 +09:00
sql xml2: Fix failure with xslt_process() under -fsanitize=undefined 2026-03-13 16:06:28 +09:00
.gitignore Support "make check" in contrib 2011-04-25 22:27:11 +03:00
Makefile contrib/xml2: Use SQL-standard function bodies. 2024-12-29 13:53:00 -05:00
meson.build Update copyright for 2026 2026-01-01 13:24:10 -05:00
xml2--1.0--1.1.sql Update xml2 extension for parallel query. 2016-06-14 15:49:32 -04:00
xml2--1.1--1.2.sql contrib/xml2: Use SQL-standard function bodies. 2024-12-29 13:53:00 -05:00
xml2--1.1.sql Update xml2 extension for parallel query. 2016-06-14 15:49:32 -04:00
xml2.control contrib/xml2: Use SQL-standard function bodies. 2024-12-29 13:53:00 -05:00
xpath.c xml2: Fix more memory leaks with libxml2 and XPath evaluations 2026-06-03 08:16:42 +09:00
xslt_proc.c xml2: Fix failure with xslt_process() under -fsanitize=undefined 2026-03-13 16:06:28 +09:00