[misc] Make sure files are closed