Ran a static analyzer and fixed some problems

This is against master-1.2 since that is the default branch. I can run it against other branches if you like.