Fix inf. loop when handling syscall

Tried to create a test case for this issue but couldn't reproduce the issue.