Fix infinite loop, though it stops with segmentation fault.