Jim Jones <jim.jo...@uni-muenster.de> writes:
> On 21.05.25 22:20, Tom Lane wrote:
>> 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 xmlsoft examples are a bit misleading though [1]

Yeah.  I also did some searching on http://codesearch.debian.net
and was hard put to it to find anything that pays attention to
xmlDocSetRootElement's result at all.  I wonder how many of those
represent leaks.

> It seems that xml_parse has the same issue[3]

I did look at that one too.  I think it's fine, because we're
dealing with a newly-created document which can't have a root node
yet.  (Reinforcing this, Valgrind sees no leaks after applying
my patch.)  I considered adding an assertion that that call returns
NULL, but concluded that it wasn't worth the notational hassle.
I'm not strongly set on that conclusion, though, if you think
differently.

                        regards, tom lane


Reply via email to