Ensure we close opened files

Change-Id: I74d8e817b10c353a61732e4e842666eb24a1ed54