Fix issues pointed out by clang-analyzer

This fixes all clang-analyzer warnings besides `tree.h`-related ones and the one in `tty.c`, which would break Darwin.

We went down from this:
![2014-09-27-005350_1920x1080_scrot](https://cloud.githubusercontent.com/assets/692459/4428676/f94fd806-45cf-11e4-88bd-995e2aff7c24.png)

To this:
![2014-09-27-005347_1920x1080_scrot](https://cloud.githubusercontent.com/assets/692459/4428680/02a23cf0-45d0-11e4-9183-c24c2da913fb.png)