[FIXED JENKINS-18351] Better fix for file handle leak.