Fixed FD leak when replaying file in a loop