Fix several memory leaks found by Coverity
There is a (sadly, private) Red Hat bug about Coverity analysis of libxml2: https://bugzilla.redhat.com/show_bug.cgi?id=1938806
There are quite a few potential, small memory leaks, mostly in error paths, that Coverity found. I suspect that it is difficult to trigger a lot of these. I have compile-tested the fixes, but nothing more.