Make sure that file handle is freed when an error is raised to prevent access exception on subsequent deletion attempt.
Authored by: emassip 2012-07-10
Parent: [r9969]
Child: [r9971]