(make_keys): clean-up salting loop and try not to leak memory

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@9197 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-11-15 23:13:30 +00:00
parent e0a6466c6e
commit 03594ac148

View File

@@ -56,7 +56,7 @@ make_keys(krb5_context context, krb5_principal principal, const char *password,
krb5_enctype e; krb5_enctype e;
krb5_error_code ret; krb5_error_code ret = 0;
char **ktypes, **kp; char **ktypes, **kp;
Key *keys = NULL, *tmp; Key *keys = NULL, *tmp;
@@ -179,24 +179,32 @@ make_keys(krb5_context context, krb5_principal principal, const char *password,
if(ret) if(ret)
goto out; goto out;
if (salt_set) { if (salt.salttype != KRB5_PW_SALT || salt_set) {
/* is the salt has not been set explicitly, it will be
the default salt, so there's no need to explicitly
copy it */
key.salt = malloc (sizeof(*key.salt)); key.salt = malloc (sizeof(*key.salt));
if (key.salt == NULL) { if (key.salt == NULL) {
free_Key(&key);
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }
key.salt->type = salt.salttype; key.salt->type = salt.salttype;
krb5_data_zero (&key.salt->salt);
/* is the salt has not been set explicitly, it will be
the default salt, so there's no need to explicitly
copy it */
if (salt_set) {
ret = krb5_data_copy(&key.salt->salt, ret = krb5_data_copy(&key.salt->salt,
salt.saltvalue.data, salt.saltvalue.data,
salt.saltvalue.length); salt.saltvalue.length);
if (ret) if (ret) {
free_Key(&key);
goto out; goto out;
} }
}
}
tmp = realloc(keys, (num_keys + 1) * sizeof(*keys)); tmp = realloc(keys, (num_keys + 1) * sizeof(*keys));
if(tmp == NULL) { if(tmp == NULL) {
free_Key(&key);
ret = ENOMEM; ret = ENOMEM;
goto out; goto out;
} }