fix random crash with -cov

Overwriting the file name before closing the opened file causes failures deep within Windows API.