Asan fixes

I ran `make check` under -fsanitize=address, and it found a few minor issues.