Fixed fclose call in generator

The opened file in the generator hasn't been closed when used in a loop
and the loop was ended with a break (so in nearly all cases)