Fix more memory leaks and potential null-pointer dereferences found by t...

...he clang static analyzer.