Properly dispose the file stream

Attempt to fix Coverity issue #18126