Re: [PATCH] Add pretty-printed XML output option

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jim Jones <jim.jones@uni-muenster.de>
Cc: Peter Smith <smithpb2250@gmail.com>, Peter Eisentraut <peter.eisentraut@enterprisedb.com>, Nikolay Samokhvalov <samokhvalov@gmail.com>, PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Andrey Borodin <amborodin86@gmail.com>
Date: 2025-05-21T20:20:17Z
Lists: pgsql-hackers

Attachments

Jim Jones <jim.jones@uni-muenster.de> writes:
> In my environment (libxml2 v2.9.10 and Ubuntu 22.04) I couldn't 
> reproduce this memory leak.

Just when you thought it was safe to go back in the water ...

Experimenting with the improved valgrind leak detection code at [1],
I discovered that XMLSERIALIZE(... INDENT) has yet a different memory
leak problem.  It turns out that xmlDocSetRootElement() doesn't
merely install the given root node: it unlinks the document's old
root node and returns it to you.  If you don't free it, it's leaked
(for the session, since this is a malloc not palloc).  The amount of
leakage isn't that large, seems to be a couple hundred bytes per
iteration, which may explain why this escaped our notice in the
previous testing.  Still, it could add up under extensive usage.
So I think we need to apply the attached, back to PG 16.

			regards, tom lane

[1] https://www.postgresql.org/message-id/1295385.1747847681%40sss.pgh.pa.us

Commits

  1. Fix memory leak in XMLSERIALIZE(... INDENT).

  2. doc: Move documentation of md5_password_warnings to a better place

  3. Support [NO] INDENT option in XMLSERIALIZE().

  4. Add an expected-file to match behavior of latest libxml2.