close the file before destroying the handle