]> git.ipfire.org Git - thirdparty/postgresql.git/commit
Fix memory leak in XMLSERIALIZE(... INDENT).
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 May 2025 17:52:46 +0000 (13:52 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 22 May 2025 17:52:46 +0000 (13:52 -0400)
commitee58de10084b42a24aaa3ab4af7713bb2fe02ab4
tree0ae77dd219b36d87b4571b6f094c3481b345c04b
parent0d2063585876e1333956ae8e3b5efae4b0cff083
Fix memory leak in XMLSERIALIZE(... INDENT).

xmltotext_with_options sometimes tries to replace the existing
root node of a libxml2 document.  In that case xmlDocSetRootElement
will unlink and return the old root node; if we fail to free it,
it's leaked for the remainder of the session.  The amount of memory
at stake is not large, a couple hundred bytes per occurrence, but
that could still become annoying in heavy usage.

Our only other xmlDocSetRootElement call is not at risk because
it's working on a just-created document, but let's modify that
code too to make it clear that it's dependent on that.

Author: Tom Lane <tgl@sss.pgh.pa.us>
Reviewed-by: Jim Jones <jim.jones@uni-muenster.de>
Discussion: https://postgr.es/m/1358967.1747858817@sss.pgh.pa.us
Backpatch-through: 16
src/backend/utils/adt/xml.c