main-loop: check return value before using pointer