Fix ASAN related crashes

These crashes were found using GCC 4.8.0.