From: Ken Raeburn Date: Sun, 14 Mar 2004 04:27:08 +0000 (+0000) Subject: Change profile code over to new thread macros, and enable data sharing always X-Git-Tag: krb5-1.4-beta1~549 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7b6a6167c1dd23bf551e34c43362fac658227ce1;p=krb5.git Change profile code over to new thread macros, and enable data sharing always * prof_int.h: Include k5-thread.h. Don't include sys/types.h and pthread.h. (SHARE_TREE_DATA): Always define. (USE_PTHREADS): Don't define. (prof_mutex_lock, prof_mutex_unlock): Deleted. (struct global_shared_profile_data): Change mutex to use k5_mutex_t instead of pthread_mutex_t. (g_shared_trees_mutex): Don't conditionalize on USE_PTHREADS. * prof_file.c (krb5int_profile_shared_data): Initialize mutex. (profile_open_file, profile_dereference_data): Use new mutex macros. Check return status when locking. Fix a potential memory leak in an error case. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16163 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/util/profile/ChangeLog b/src/util/profile/ChangeLog index e71809f9a..8f6a02cee 100644 --- a/src/util/profile/ChangeLog +++ b/src/util/profile/ChangeLog @@ -1,3 +1,18 @@ +2004-03-13 Ken Raeburn + + * prof_int.h: Include k5-thread.h. Don't include sys/types.h and + pthread.h. + (SHARE_TREE_DATA): Always define. + (USE_PTHREADS): Don't define. + (prof_mutex_lock, prof_mutex_unlock): Deleted. + (struct global_shared_profile_data): Change mutex to use + k5_mutex_t instead of pthread_mutex_t. + (g_shared_trees_mutex): Don't conditionalize on USE_PTHREADS. + * prof_file.c (krb5int_profile_shared_data): Initialize mutex. + (profile_open_file, profile_dereference_data): Use new mutex + macros. Check return status when locking. Fix a potential memory + leak in an error case. + 2004-03-08 Ezra Peisach * prof_get.c (profile_parse_boolean): Declare first argument as diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index 23c64b4c6..1141127a1 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -29,7 +29,8 @@ #ifdef SHARE_TREE_DATA struct global_shared_profile_data krb5int_profile_shared_data = { - 0 + 0, + K5_MUTEX_INITIALIZER }; #endif @@ -128,7 +129,12 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, memcpy(expanded_filename, filespec, len); #ifdef SHARE_TREE_DATA - (void) prof_mutex_lock(&g_shared_trees_mutex); + retval = k5_mutex_lock(&g_shared_trees_mutex); + if (retval) { + free(expanded_filename); + free(prf); + return retval; + } for (data = g_shared_trees; data; data = data->next) { if (!strcmp(data->filespec, expanded_filename) /* Check that current uid has read access. */ @@ -138,16 +144,17 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, if (data) { retval = profile_update_file_data(data); data->refcount++; - (void) prof_mutex_unlock(&g_shared_trees_mutex); + (void) k5_mutex_unlock(&g_shared_trees_mutex); free(expanded_filename); prf->data = data; *ret_prof = prf; return retval; } - (void) prof_mutex_unlock(&g_shared_trees_mutex); + (void) k5_mutex_unlock(&g_shared_trees_mutex); data = malloc(sizeof(struct _prf_data_t)); if (data == NULL) { free(prf); + free(expanded_filename); return ENOMEM; } memset(data, 0, sizeof(*data)); @@ -168,11 +175,15 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, } #ifdef SHARE_TREE_DATA + retval = k5_mutex_lock(&g_shared_trees_mutex); + if (retval) { + profile_close_file(prf); + return retval; + } data->flags |= PROFILE_FILE_SHARED; - (void) prof_mutex_lock(&g_shared_trees_mutex); data->next = g_shared_trees; g_shared_trees = data; - (void) prof_mutex_unlock(&g_shared_trees_mutex); + (void) k5_mutex_unlock(&g_shared_trees_mutex); #endif *ret_prof = prf; @@ -330,11 +341,14 @@ errout: void profile_dereference_data(prf_data_t data) { #ifdef SHARE_TREE_DATA - (void) prof_mutex_lock(&g_shared_trees_mutex); + int err; + err = k5_mutex_lock(&g_shared_trees_mutex); + if (err) + return; data->refcount--; if (data->refcount == 0) profile_free_file_data(data); - (void) prof_mutex_unlock(&g_shared_trees_mutex); + (void) k5_mutex_unlock(&g_shared_trees_mutex); #else profile_free_file_data(data); #endif diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h index 919141168..a0d90b5e2 100644 --- a/src/util/profile/prof_int.h +++ b/src/util/profile/prof_int.h @@ -7,16 +7,12 @@ #if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) #include -#define USE_PTHREADS #define PROFILE_SUPPORTS_FOREIGN_NEWLINES -#define SHARE_TREE_DATA #endif -#if defined(USE_PTHREADS) -#include -#include -#endif +#define SHARE_TREE_DATA +#include "k5-thread.h" #include "com_err.h" #include "profile.h" @@ -62,23 +58,12 @@ typedef struct _prf_file_t *prf_file_t; struct global_shared_profile_data { /* This is the head of the global list of shared trees */ prf_data_t trees; -#ifdef USE_PTHREADS /* Lock for above list. */ - pthread_mutex_t mutex; -#endif + k5_mutex_t mutex; }; extern struct global_shared_profile_data krb5int_profile_shared_data; #define g_shared_trees (krb5int_profile_shared_data.trees) - -#ifdef USE_PTHREADS -#include #define g_shared_trees_mutex (krb5int_profile_shared_data.mutex) -#define prof_mutex_lock(L) (pthread_mutex_lock(L)) -#define prof_mutex_unlock(L) (pthread_mutex_unlock(L)) -#else -#define prof_mutex_lock(L) (0) -#define prof_mutex_unlock(L) (0) -#endif #endif /* SHARE_TREE_DATA */