Clean up errors turned up by Clang's address address sanitizer tool.
The most serious problems were fixed earlier, under #13380.
Running a no-data test under the address sanitizer finds more problems, mostly memory leaks when code fails to properly clean up when taking error paths. The majority of the problems are in test code, but some are in the library code itself.
To reproduce the failures,