Fix 9 memory leaks.

(Thanks to Brent Cook)

With help from tedu@

OK from tedu@
Fix a memory leak and another one that occurs in the error paths.

(Thanks to Brent Cook)


OK from tedu@