Fix file handles being left open on windows builds