fixed unclosed file memory leak