Fix some small memory leaks
Found by Coverity.
https://bugzilla.redhat.com/show_bug.cgi?id=1938851
Sadly, the above bug is private, as is the Red Hat internal Coverity instance. I am not sure if you care about the leaks in the tests, so I split those out into a separate commit.