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
- fix-leakage-in-xmlserialize-indent.patch (text/x-diff) patch
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
-
Fix memory leak in XMLSERIALIZE(... INDENT).
- f24605e2dc16 18.0 landed
- ee58de10084b 16.10 landed
- 20bae0690322 17.6 landed
-
doc: Move documentation of md5_password_warnings to a better place
- f3622b64762b 18.0 cited
-
Support [NO] INDENT option in XMLSERIALIZE().
- 483bdb2afec9 16.0 landed
-
Add an expected-file to match behavior of latest libxml2.
- 085423e3e326 9.6.0 cited