Add options to use mmap or electric fence to check memory accesses, and fix a few memory access violations.