Revised patch that properly closes the keytab in case of error.