krb5_context: embed mutex in structure
Instead of allocating a separate mutex object on the heap, include the HEIMDAL_MUTEX in the krb5_context structure. Change-Id: If6db484177410487176985e43e3b43e0f2166518
This commit is contained in:

committed by
Jeffrey Altman

parent
1f53a40827
commit
c80816f9c3
@@ -422,12 +422,7 @@ krb5_init_context(krb5_context *context)
|
||||
if(!p)
|
||||
return ENOMEM;
|
||||
|
||||
p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
|
||||
if (p->mutex == NULL) {
|
||||
free(p);
|
||||
return ENOMEM;
|
||||
}
|
||||
HEIMDAL_MUTEX_init(p->mutex);
|
||||
HEIMDAL_MUTEX_init(&p->mutex);
|
||||
|
||||
p->flags |= KRB5_CTX_F_HOMEDIR_ACCESS;
|
||||
|
||||
@@ -520,13 +515,7 @@ krb5_copy_context(krb5_context context, krb5_context *out)
|
||||
if (p == NULL)
|
||||
return krb5_enomem(context);
|
||||
|
||||
p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
|
||||
if (p->mutex == NULL) {
|
||||
free(p);
|
||||
return krb5_enomem(context);
|
||||
}
|
||||
HEIMDAL_MUTEX_init(p->mutex);
|
||||
|
||||
HEIMDAL_MUTEX_init(&p->mutex);
|
||||
|
||||
if (context->default_cc_name)
|
||||
p->default_cc_name = strdup(context->default_cc_name);
|
||||
@@ -627,8 +616,7 @@ krb5_free_context(krb5_context context)
|
||||
hx509_context_free(&context->hx509ctx);
|
||||
#endif
|
||||
|
||||
HEIMDAL_MUTEX_destroy(context->mutex);
|
||||
free(context->mutex);
|
||||
HEIMDAL_MUTEX_destroy(&context->mutex);
|
||||
if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) {
|
||||
rk_SOCK_EXIT();
|
||||
}
|
||||
|
@@ -49,12 +49,7 @@ krb5_init_context(krb5_context *context)
|
||||
if(!p)
|
||||
return ENOMEM;
|
||||
|
||||
p->mutex = malloc(sizeof(HEIMDAL_MUTEX));
|
||||
if (p->mutex == NULL) {
|
||||
free(p);
|
||||
return ENOMEM;
|
||||
}
|
||||
HEIMDAL_MUTEX_init(p->mutex);
|
||||
HEIMDAL_MUTEX_init(&p->mutex);
|
||||
|
||||
*context = p;
|
||||
return 0;
|
||||
@@ -65,8 +60,7 @@ krb5_free_context(krb5_context context)
|
||||
{
|
||||
krb5_clear_error_message(context);
|
||||
|
||||
HEIMDAL_MUTEX_destroy(context->mutex);
|
||||
free(context->mutex);
|
||||
HEIMDAL_MUTEX_destroy(&context->mutex);
|
||||
if (context->flags & KRB5_CTX_F_SOCKETS_INITIALIZED) {
|
||||
rk_SOCK_EXIT();
|
||||
}
|
||||
|
@@ -623,10 +623,10 @@ krb5_get_error_string(krb5_context context)
|
||||
{
|
||||
char *ret = NULL;
|
||||
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
if (context->error_string)
|
||||
ret = strdup(context->error_string);
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -635,9 +635,9 @@ krb5_have_error_string(krb5_context context)
|
||||
KRB5_DEPRECATED_FUNCTION("Use krb5_get_error_message instead")
|
||||
{
|
||||
char *str;
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
str = context->error_string;
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
return str != NULL;
|
||||
}
|
||||
|
||||
|
@@ -47,12 +47,12 @@
|
||||
KRB5_LIB_FUNCTION void KRB5_LIB_CALL
|
||||
krb5_clear_error_message(krb5_context context)
|
||||
{
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
if (context->error_string)
|
||||
free(context->error_string);
|
||||
context->error_code = 0;
|
||||
context->error_string = NULL;
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,7 +105,7 @@ krb5_vset_error_message (krb5_context context, krb5_error_code ret,
|
||||
if (context == NULL)
|
||||
return;
|
||||
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
if (context->error_string) {
|
||||
free(context->error_string);
|
||||
context->error_string = NULL;
|
||||
@@ -114,7 +114,7 @@ krb5_vset_error_message (krb5_context context, krb5_error_code ret,
|
||||
r = vasprintf(&context->error_string, fmt, args);
|
||||
if (r < 0)
|
||||
context->error_string = NULL;
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
if (context->error_string)
|
||||
_krb5_debug(context, 100, "error message: %s: %d", context->error_string, ret);
|
||||
}
|
||||
@@ -168,13 +168,13 @@ krb5_vprepend_error_message(krb5_context context, krb5_error_code ret,
|
||||
if (context == NULL)
|
||||
return;
|
||||
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
if (context->error_code != ret) {
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
return;
|
||||
}
|
||||
if (vasprintf(&str, fmt, args) < 0 || str == NULL) {
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
return;
|
||||
}
|
||||
if (context->error_string) {
|
||||
@@ -189,7 +189,7 @@ krb5_vprepend_error_message(krb5_context context, krb5_error_code ret,
|
||||
free(str);
|
||||
} else
|
||||
context->error_string = str;
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,13 +226,13 @@ krb5_get_error_message(krb5_context context, krb5_error_code code)
|
||||
*/
|
||||
if (context)
|
||||
{
|
||||
HEIMDAL_MUTEX_lock(context->mutex);
|
||||
HEIMDAL_MUTEX_lock(&context->mutex);
|
||||
if (context->error_string &&
|
||||
(code == context->error_code || context->error_code == 0))
|
||||
{
|
||||
str = strdup(context->error_string);
|
||||
}
|
||||
HEIMDAL_MUTEX_unlock(context->mutex);
|
||||
HEIMDAL_MUTEX_unlock(&context->mutex);
|
||||
|
||||
if (str)
|
||||
return str;
|
||||
|
@@ -292,7 +292,7 @@ typedef struct krb5_context_data {
|
||||
char *default_cc_name;
|
||||
char *default_cc_name_env;
|
||||
int default_cc_name_set;
|
||||
void *mutex; /* protects error_string */
|
||||
HEIMDAL_MUTEX mutex; /* protects error_string */
|
||||
int large_msg_size;
|
||||
int max_msg_size;
|
||||
int tgs_negative_timeout; /* timeout for TGS negative cache */
|
||||
|
Reference in New Issue
Block a user