Change profile code over to new thread macros, and enable data sharing always
authorKen Raeburn <raeburn@mit.edu>
Sun, 14 Mar 2004 04:27:08 +0000 (04:27 +0000)
committerKen Raeburn <raeburn@mit.edu>
Sun, 14 Mar 2004 04:27:08 +0000 (04:27 +0000)
* 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

src/util/profile/ChangeLog
src/util/profile/prof_file.c
src/util/profile/prof_int.h

index e71809f9aed510bb56714188ef92f2f527bd8a3e..8f6a02cee2e9cb2688e954d94876abf5a07f5cdb 100644 (file)
@@ -1,3 +1,18 @@
+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
index 23c64b4c611f9a159d3f8860f31211abd977f255..1141127a1c03bd432164ab4c8cc57de8c3917d1a 100644 (file)
@@ -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
index 919141168f89ae974e2625ef9e4b7c4078ad75c1..a0d90b5e206460ee9feef8aa185d05bbe5c68377 100644 (file)
@@ -7,16 +7,12 @@
 
 #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"
 
@@ -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 <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 */