diff options
author | Greg Hudson <ghudson@mit.edu> | 2009-04-30 17:28:55 +0000 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2009-04-30 17:28:55 +0000 |
commit | a4cef664aad9b21da014bc37308f3da3bf18e675 (patch) | |
tree | ed1bc54fe553eea381c1237d7a975913622c20d7 /src/lib/krb5/keytab | |
parent | 3794fb8ccd011e91fd8f214547780fdd58df39a4 (diff) | |
download | krb5-a4cef664aad9b21da014bc37308f3da3bf18e675.tar.gz krb5-a4cef664aad9b21da014bc37308f3da3bf18e675.tar.xz krb5-a4cef664aad9b21da014bc37308f3da3bf18e675.zip |
In ktfile_common_resolve, set the output pointer to NULL on error, and
use a cleanup label instead of freeing the same resources in multiple
error handling blocks.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@22296 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/krb5/keytab')
-rw-r--r-- | src/lib/krb5/keytab/kt_file.c | 54 |
1 files changed, 29 insertions, 25 deletions
diff --git a/src/lib/krb5/keytab/kt_file.c b/src/lib/krb5/keytab/kt_file.c index 2aaa9b9ab2..bb2d838d3d 100644 --- a/src/lib/krb5/keytab/kt_file.c +++ b/src/lib/krb5/keytab/kt_file.c @@ -200,41 +200,45 @@ static krb5_error_code krb5_ktfileint_find_slot static krb5_error_code ktfile_common_resolve(krb5_context context, const char *name, - krb5_keytab *id, const struct _krb5_kt_ops *ops) + krb5_keytab *idptr, const struct _krb5_kt_ops *ops) { - krb5_ktfile_data *data; - krb5_error_code err; + krb5_ktfile_data *data = NULL; + krb5_error_code err = ENOMEM; + krb5_keytab id; - if ((*id = (krb5_keytab) malloc(sizeof(**id))) == NULL) - return(ENOMEM); + *idptr = NULL; + + id = calloc(1, sizeof(*id)); + if (id == NULL) + return ENOMEM; - (*id)->ops = ops; - if ((data = (krb5_ktfile_data *)malloc(sizeof(krb5_ktfile_data))) == NULL) { - free(*id); - return(ENOMEM); - } + id->ops = ops; + data = calloc(1, sizeof(krb5_ktfile_data)); + if (data == NULL) + goto cleanup; - err = k5_mutex_init(&data->lock); - if (err) { - free(data); - free(*id); - return err; - } + data->name = strdup(name); + if (data->name == NULL) + goto cleanup; - if ((data->name = strdup(name)) == NULL) { - k5_mutex_destroy(&data->lock); - free(data); - free(*id); - return(ENOMEM); - } + err = k5_mutex_init(&data->lock); + if (err) + goto cleanup; data->openf = 0; data->version = 0; data->iter_count = 0; - (*id)->data = (krb5_pointer)data; - (*id)->magic = KV5M_KEYTAB; - return(0); + id->data = (krb5_pointer) data; + id->magic = KV5M_KEYTAB; + *idptr = id; + return 0; +cleanup: + if (data) + free(data->name); + free(data); + free(id); + return err; } static krb5_error_code KRB5_CALLCONV |