context = calloc(1, sizeof(*context));
if (kcontext == NULL) {
- if (tables != NULL)
- krb5int_free_plugin_dir_data(tables);
- krb5int_close_plugin_dirs(&context->plugins);
- return ENOMEM;
+ code = ENOMEM;
+ goto cleanup;
}
context->magic = KV5M_AUTHDATA_CONTEXT;
context->modules = calloc(n_modules, sizeof(context->modules[0]));
if (context->modules == NULL) {
- if (tables != NULL)
- krb5int_free_plugin_dir_data(tables);
- krb5int_close_plugin_dirs(&context->plugins);
- free(kcontext);
- return ENOMEM;
+ code = ENOMEM;
+ goto cleanup;
}
context->n_modules = n_modules;
for (i = 0, k = 0, code = 0; i < n_tables - internal_count; i++) {
code = k5_ad_init_modules(kcontext, context, tables[i], &k);
if (code != 0)
- break;
+ goto cleanup;
}
- if (code == 0) {
- for (i = 0; i < internal_count; i++) {
- code = k5_ad_init_modules(kcontext, context, authdata_systems[i], &k);
- if (code != 0)
- break;
- }
+ for (i = 0; i < internal_count; i++) {
+ code = k5_ad_init_modules(kcontext, context, authdata_systems[i], &k);
+ if (code != 0)
+ goto cleanup;
}
+ context->plugins = plugins;
+
+cleanup:
if (tables != NULL)
krb5int_free_plugin_dir_data(tables);
- context->plugins = plugins;
-
- if (code != 0)
+ if (code != 0) {
+ krb5int_close_plugin_dirs(&plugins);
krb5_authdata_context_free(kcontext, context);
- else
+ } else {
+ /* plugins is owned by context now */
*pcontext = context;
+ }
return code;
}
if (authdata != NULL)
authdata[len] = NULL;
+ if (code != 0) {
+ krb5_free_authdata(kcontext, authdata);
+ return code;
+ }
+
*pauthdata = authdata;
- return code;
+ return 0;
}
krb5_error_code
req->ticket);
if (retval == 0) {
- krb5_principal tmp;
+ krb5_principal tmp = NULL;
/*
* We overwrite ticket->server to be the principal
if (retval == 0) {
krb5_free_principal(context, req->ticket->server);
req->ticket->server = tmp;
+ } else {
+ krb5_free_principal(context, tmp);
}
(void) krb5_free_keytab_entry_contents(context, &ktent);
break;