Fix ASAN related crashes

These crashes were found using GCC 4.8.0.

I didn't want to commit these fixes without a review.