fix a few clang-static analyzer complaints in 0.2.2

I started working on a branch to fix some clang complaints. Here's a checkpoint progress because a release is supposed to happen soon