Fix leaked file handle