Made sure the process handle is closed even if there is an error.