Fix memory corruption found by Phil.