+2004-03-13 Ken Raeburn <raeburn@mit.edu>
+
+ * 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 <epeisach@mit.edu>
* prof_get.c (profile_parse_boolean): Declare first argument as
#ifdef SHARE_TREE_DATA
struct global_shared_profile_data krb5int_profile_shared_data = {
- 0
+ 0,
+ K5_MUTEX_INITIALIZER
};
#endif
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. */
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));
}
#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;
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
#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
#include <TargetConditionals.h>
-#define USE_PTHREADS
#define PROFILE_SUPPORTS_FOREIGN_NEWLINES
-#define SHARE_TREE_DATA
#endif
-#if defined(USE_PTHREADS)
-#include <sys/types.h>
-#include <pthread.h>
-#endif
+#define SHARE_TREE_DATA
+#include "k5-thread.h"
#include "com_err.h"
#include "profile.h"
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 <pthread.h>
#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 */