krb5 commit: Assume mutex locking cannot fail

Greg Hudson ghudson at MIT.EDU
Tue May 14 13:31:57 EDT 2013


https://github.com/krb5/krb5/commit/6350fd0c909d84c00200885e722cc902049ada05
commit 6350fd0c909d84c00200885e722cc902049ada05
Author: Greg Hudson <ghudson at mit.edu>
Date:   Fri May 10 14:01:48 2013 -0400

    Assume mutex locking cannot fail
    
    Locking and unlocking a non-recursive mutex is a simple memory
    operation and should not fail on any reasonable platform with correct
    usage.  A pthread mutex can return EDEADLK on lock or EPERM on unlock,
    or EINVAL if the mutex is uninitialized, but all of these conditions
    would reflect serious bugs in the calling code.
    
    Change the k5_mutex_lock and k5_mutex_unlock wrappers to return void
    and adjust all call sites.  Propagate this change through
    k5_cc_mutex_lock and k5_cc_mutex_unlock as well.

 src/include/k5-thread.h                          |   24 ++---
 src/lib/crypto/krb/prng_fortuna.c                |    9 +--
 src/lib/gssapi/generic/util_errmap.c             |   13 +--
 src/lib/gssapi/krb5/acquire_cred.c               |   12 +--
 src/lib/gssapi/krb5/copy_ccache.c                |    6 +-
 src/lib/gssapi/krb5/init_sec_context.c           |    9 +--
 src/lib/gssapi/krb5/naming_exts.c                |   56 ++---------
 src/lib/gssapi/krb5/s4u_gss_glue.c               |    6 +-
 src/lib/gssapi/krb5/set_allowable_enctypes.c     |   10 +--
 src/lib/gssapi/krb5/val_cred.c                   |    7 +-
 src/lib/gssapi/mechglue/g_initialize.c           |   64 +++++-------
 src/lib/kdb/kdb5.c                               |    7 +-
 src/lib/krb5/ccache/cc-int.h                     |    8 +-
 src/lib/krb5/ccache/cc_file.c                    |   94 ++++-------------
 src/lib/krb5/ccache/cc_keyring.c                 |   57 ++++-------
 src/lib/krb5/ccache/cc_memory.c                  |   94 +++++-------------
 src/lib/krb5/ccache/ccbase.c                     |  119 +++++-----------------
 src/lib/krb5/keytab/kt_file.c                    |   24 +----
 src/lib/krb5/keytab/kt_memory.c                  |   40 ++------
 src/lib/krb5/keytab/ktbase.c                     |    9 +--
 src/lib/krb5/os/c_ustime.c                       |    4 +-
 src/lib/krb5/rcache/rc_base.c                    |   10 +--
 src/lib/krb5/rcache/rc_dfl.c                     |   32 ++----
 src/plugins/kdb/db2/db2_exp.c                    |   10 +-
 src/plugins/kdb/db2/kdb_db2.c                    |   15 +--
 src/plugins/kdb/ldap/libkdb_ldap/kdb_ldap_conn.c |    4 +-
 src/plugins/kdb/ldap/libkdb_ldap/ldap_handle.c   |   15 +--
 src/util/et/com_err.c                            |   14 +--
 src/util/et/error_message.c                      |   26 ++----
 src/util/profile/prof_file.c                     |   59 ++++-------
 src/util/profile/prof_init.c                     |   15 +--
 src/util/profile/prof_int.h                      |    4 +-
 src/util/profile/prof_set.c                      |   16 +--
 src/util/profile/prof_tree.c                     |   34 ++-----
 src/util/support/errors.c                        |   10 +-
 src/util/support/threads.c                       |   96 ++++++++----------
 36 files changed, 296 insertions(+), 736 deletions(-)

diff --git a/src/include/k5-thread.h b/src/include/k5-thread.h
index 17ef69e..1b7fa69 100644
--- a/src/include/k5-thread.h
+++ b/src/include/k5-thread.h
@@ -378,17 +378,17 @@ static inline int k5_mutex_finish_init(k5_mutex_t *m)
 #define k5_mutex_destroy(M)                     \
     (k5_os_mutex_destroy(M))
 
-#if __GNUC__ >= 4
-static int k5_mutex_lock(k5_mutex_t *)
-    __attribute__((warn_unused_result));
-#endif
-static inline int k5_mutex_lock(k5_mutex_t *m)
+static inline void k5_mutex_lock(k5_mutex_t *m)
 {
-    return k5_os_mutex_lock(m);
+    int r = k5_os_mutex_lock(m);
+    assert(r == 0);
 }
 
-#define k5_mutex_unlock(M)                      \
-    (k5_os_mutex_unlock(M))
+static inline void k5_mutex_unlock(k5_mutex_t *m)
+{
+    int r = k5_os_mutex_unlock(m);
+    assert(r == 0);
+}
 
 #define k5_mutex_assert_locked(M)       ((void)(M))
 #define k5_mutex_assert_unlocked(M)     ((void)(M))
@@ -423,12 +423,8 @@ extern int k5_key_delete(k5_key_t);
 
 extern int  KRB5_CALLCONV krb5int_mutex_alloc  (k5_mutex_t **);
 extern void KRB5_CALLCONV krb5int_mutex_free   (k5_mutex_t *);
-extern int  KRB5_CALLCONV krb5int_mutex_lock   (k5_mutex_t *)
-#if __GNUC__ >= 4
-    __attribute__((warn_unused_result))
-#endif
-    ;
-extern int  KRB5_CALLCONV krb5int_mutex_unlock (k5_mutex_t *);
+extern void KRB5_CALLCONV krb5int_mutex_lock   (k5_mutex_t *);
+extern void KRB5_CALLCONV krb5int_mutex_unlock (k5_mutex_t *);
 
 /* In time, many of the definitions above should move into the support
    library, and this file should be greatly simplified.  For type
diff --git a/src/lib/crypto/krb/prng_fortuna.c b/src/lib/crypto/krb/prng_fortuna.c
index 8b96a40..2a54872 100644
--- a/src/lib/crypto/krb/prng_fortuna.c
+++ b/src/lib/crypto/krb/prng_fortuna.c
@@ -391,9 +391,7 @@ krb5_c_random_add_entropy(krb5_context context, unsigned int randsource,
     ret = krb5int_crypto_init();
     if (ret)
         return ret;
-    ret = k5_mutex_lock(&fortuna_lock);
-    if (ret)
-        return ret;
+    k5_mutex_lock(&fortuna_lock);
     if (randsource == KRB5_C_RANDSOURCE_OSRAND ||
         randsource == KRB5_C_RANDSOURCE_TRUSTEDPARTY) {
         /* These sources contain enough entropy that we should use them
@@ -414,7 +412,6 @@ krb5_c_random_add_entropy(krb5_context context, unsigned int randsource,
 krb5_error_code KRB5_CALLCONV
 krb5_c_random_make_octets(krb5_context context, krb5_data *outdata)
 {
-    krb5_error_code ret;
 #ifdef _WIN32
     DWORD pid = GetCurrentProcessId();
 #else
@@ -422,9 +419,7 @@ krb5_c_random_make_octets(krb5_context context, krb5_data *outdata)
 #endif
     unsigned char pidbuf[4];
 
-    ret = k5_mutex_lock(&fortuna_lock);
-    if (ret)
-        return ret;
+    k5_mutex_lock(&fortuna_lock);
 
     if (!have_entropy) {
         k5_mutex_unlock(&fortuna_lock);
diff --git a/src/lib/gssapi/generic/util_errmap.c b/src/lib/gssapi/generic/util_errmap.c
index c26ea7b..628a455 100644
--- a/src/lib/gssapi/generic/util_errmap.c
+++ b/src/lib/gssapi/generic/util_errmap.c
@@ -183,13 +183,7 @@ OM_uint32 gssint_mecherrmap_map(OM_uint32 minor, const gss_OID_desc * oid)
 
     me.code = minor;
     me.mech = *oid;
-    err = k5_mutex_lock(&mutex);
-    if (err) {
-#ifdef DEBUG
-        if (f != stderr) fclose(f);
-#endif
-        return 0;
-    }
+    k5_mutex_lock(&mutex);
 
     /* Is this status+oid already mapped?  */
     p = mecherrmap_findright(&m, me);
@@ -254,14 +248,11 @@ int gssint_mecherrmap_get(OM_uint32 minor, gss_OID mech_oid,
                           OM_uint32 *mech_minor)
 {
     const struct mecherror *p;
-    int err;
 
     if (minor == 0) {
         return EINVAL;
     }
-    err = k5_mutex_lock(&mutex);
-    if (err)
-        return err;
+    k5_mutex_lock(&mutex);
     p = mecherrmap_findleft(&m, minor);
     k5_mutex_unlock(&mutex);
     if (!p) {
diff --git a/src/lib/gssapi/krb5/acquire_cred.c b/src/lib/gssapi/krb5/acquire_cred.c
index dbc5a70..0efcad4 100644
--- a/src/lib/gssapi/krb5/acquire_cred.c
+++ b/src/lib/gssapi/krb5/acquire_cred.c
@@ -112,11 +112,7 @@ gss_krb5int_register_acceptor_identity(OM_uint32 *minor_status,
             return GSS_S_FAILURE;
     }
 
-    err = k5_mutex_lock(&gssint_krb5_keytab_lock);
-    if (err) {
-        free(new);
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&gssint_krb5_keytab_lock);
     old = krb5_gss_keytab;
     krb5_gss_keytab = new;
     k5_mutex_unlock(&gssint_krb5_keytab_lock);
@@ -196,11 +192,7 @@ acquire_accept_cred(krb5_context context,
     if (req_keytab != NULL) {
         code = krb5_kt_dup(context, req_keytab, &kt);
     } else {
-        code = k5_mutex_lock(&gssint_krb5_keytab_lock);
-        if (code) {
-            *minor_status = code;
-            return GSS_S_FAILURE;
-        }
+        k5_mutex_lock(&gssint_krb5_keytab_lock);
         if (krb5_gss_keytab != NULL) {
             code = krb5_kt_resolve(context, krb5_gss_keytab, &kt);
             k5_mutex_unlock(&gssint_krb5_keytab_lock);
diff --git a/src/lib/gssapi/krb5/copy_ccache.c b/src/lib/gssapi/krb5/copy_ccache.c
index fbb7a48..f3d7666 100644
--- a/src/lib/gssapi/krb5/copy_ccache.c
+++ b/src/lib/gssapi/krb5/copy_ccache.c
@@ -23,11 +23,7 @@ gss_krb5int_copy_ccache(OM_uint32 *minor_status,
 
     /* cred handle will have been validated by gssspi_set_cred_option() */
     k5creds = (krb5_gss_cred_id_t) *cred_handle;
-    code = k5_mutex_lock(&k5creds->lock);
-    if (code) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&k5creds->lock);
     if (k5creds->usage == GSS_C_ACCEPT) {
         k5_mutex_unlock(&k5creds->lock);
         *minor_status = (OM_uint32) G_BAD_USAGE;
diff --git a/src/lib/gssapi/krb5/init_sec_context.c b/src/lib/gssapi/krb5/init_sec_context.c
index d4c987a..1bc69ca 100644
--- a/src/lib/gssapi/krb5/init_sec_context.c
+++ b/src/lib/gssapi/krb5/init_sec_context.c
@@ -1014,9 +1014,7 @@ krb5_gss_init_context (krb5_context *ctxp)
     if (err)
         return err;
 #ifndef _WIN32
-    err = k5_mutex_lock(&kg_kdc_flag_mutex);
-    if (err)
-        return err;
+    k5_mutex_lock(&kg_kdc_flag_mutex);
     is_kdc = kdc_flag;
     k5_mutex_unlock(&kg_kdc_flag_mutex);
 
@@ -1041,10 +1039,7 @@ krb5int_gss_use_kdc_context(OM_uint32 *minor_status,
     err = gss_krb5int_initialize_library();
     if (err)
         return err;
-    *minor_status = k5_mutex_lock(&kg_kdc_flag_mutex);
-    if (*minor_status) {
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kg_kdc_flag_mutex);
     kdc_flag = 1;
     k5_mutex_unlock(&kg_kdc_flag_mutex);
     return GSS_S_COMPLETE;
diff --git a/src/lib/gssapi/krb5/naming_exts.c b/src/lib/gssapi/krb5/naming_exts.c
index f44f0d2..10dbe32 100644
--- a/src/lib/gssapi/krb5/naming_exts.c
+++ b/src/lib/gssapi/krb5/naming_exts.c
@@ -119,15 +119,10 @@ kg_duplicate_name(krb5_context context,
 {
     krb5_error_code code;
 
-    code = k5_mutex_lock(&src->lock);
-    if (code != 0)
-        return code;
-
+    k5_mutex_lock(&src->lock);
     code = kg_init_name(context, src->princ, src->service, src->host,
                         src->ad_context, 0, dst);
-
     k5_mutex_unlock(&src->lock);
-
     return code;
 }
 
@@ -282,11 +277,7 @@ krb5_gss_inquire_name(OM_uint32 *minor_status,
 
     kname = (krb5_gss_name_t)name;
 
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -343,13 +334,7 @@ krb5_gss_get_name_attribute(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        krb5_free_context(context);
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -421,12 +406,7 @@ krb5_gss_set_name_attribute(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -476,12 +456,7 @@ krb5_gss_delete_name_attribute(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -528,12 +503,7 @@ krb5_gss_map_name_to_any(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -585,12 +555,7 @@ krb5_gss_release_any_name_mapping(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     if (kname->ad_context == NULL) {
         code = krb5_authdata_context_init(context, &kname->ad_context);
@@ -646,12 +611,7 @@ krb5_gss_export_name_composite(OM_uint32 *minor_status,
     }
 
     kname = (krb5_gss_name_t)name;
-
-    code = k5_mutex_lock(&kname->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&kname->lock);
 
     code = krb5_unparse_name(context, kname->princ, &princstr);
     if (code != 0)
diff --git a/src/lib/gssapi/krb5/s4u_gss_glue.c b/src/lib/gssapi/krb5/s4u_gss_glue.c
index a7e720b..4381a84 100644
--- a/src/lib/gssapi/krb5/s4u_gss_glue.c
+++ b/src/lib/gssapi/krb5/s4u_gss_glue.c
@@ -58,11 +58,7 @@ kg_impersonate_name(OM_uint32 *minor_status,
     if (impersonator_cred->req_enctypes != NULL)
         in_creds.keyblock.enctype = impersonator_cred->req_enctypes[0];
 
-    code = k5_mutex_lock(&user->lock);
-    if (code != 0) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&user->lock);
 
     if (user->ad_context != NULL) {
         code = krb5_authdata_export_authdata(context,
diff --git a/src/lib/gssapi/krb5/set_allowable_enctypes.c b/src/lib/gssapi/krb5/set_allowable_enctypes.c
index 7ef4aee..d9fd279 100644
--- a/src/lib/gssapi/krb5/set_allowable_enctypes.c
+++ b/src/lib/gssapi/krb5/set_allowable_enctypes.c
@@ -91,9 +91,7 @@ gss_krb5int_set_allowable_enctypes(OM_uint32 *minor_status,
             }
         }
     } else {
-        kerr = k5_mutex_lock(&cred->lock);
-        if (kerr)
-            goto error_out;
+        k5_mutex_lock(&cred->lock);
         if (cred->req_enctypes)
             free(cred->req_enctypes);
         cred->req_enctypes = NULL;
@@ -110,11 +108,7 @@ gss_krb5int_set_allowable_enctypes(OM_uint32 *minor_status,
         kerr = ENOMEM;
         goto error_out;
     }
-    kerr = k5_mutex_lock(&cred->lock);
-    if (kerr) {
-        free(new_ktypes);
-        goto error_out;
-    }
+    k5_mutex_lock(&cred->lock);
     if (cred->req_enctypes)
         free(cred->req_enctypes);
     cred->req_enctypes = new_ktypes;
diff --git a/src/lib/gssapi/krb5/val_cred.c b/src/lib/gssapi/krb5/val_cred.c
index 234cf69..cb1cb93 100644
--- a/src/lib/gssapi/krb5/val_cred.c
+++ b/src/lib/gssapi/krb5/val_cred.c
@@ -37,12 +37,7 @@ krb5_gss_validate_cred_1(OM_uint32 *minor_status, gss_cred_id_t cred_handle,
     krb5_principal princ;
 
     cred = (krb5_gss_cred_id_t) cred_handle;
-
-    code = k5_mutex_lock(&cred->lock);
-    if (code) {
-        *minor_status = code;
-        return GSS_S_FAILURE;
-    }
+    k5_mutex_lock(&cred->lock);
 
     if (cred->ccache && cred->expire != 0) {
         if ((code = krb5_cc_get_principal(context, cred->ccache, &princ))) {
diff --git a/src/lib/gssapi/mechglue/g_initialize.c b/src/lib/gssapi/mechglue/g_initialize.c
index b801e12..f5b8b15 100644
--- a/src/lib/gssapi/mechglue/g_initialize.c
+++ b/src/lib/gssapi/mechglue/g_initialize.c
@@ -171,9 +171,7 @@ gss_OID *oid;
 	if (*minor_status != 0)
 		return (GSS_S_FAILURE);
 
-	*minor_status = k5_mutex_lock(&g_mechListLock);
-	if (*minor_status)
-		return GSS_S_FAILURE;
+	k5_mutex_lock(&g_mechListLock);
 	aMech = g_mechList;
 	while (aMech != NULL) {
 
@@ -252,13 +250,9 @@ gss_OID_set *mechSet_out;
 	 * need to lock the g_mechSet in case someone tries to update it while
 	 * I'm copying it.
 	 */
-	*minorStatus = k5_mutex_lock(&g_mechSetLock);
-	if (*minorStatus) {
-		return GSS_S_FAILURE;
-	}
-
+	k5_mutex_lock(&g_mechSetLock);
 	status = generic_gss_copy_oid_set(minorStatus, &g_mechSet, mechSet_out);
-	(void) k5_mutex_unlock(&g_mechSetLock);
+	k5_mutex_unlock(&g_mechSetLock);
 	return (status);
 } /* gss_indicate_mechs */
 
@@ -293,8 +287,7 @@ build_mechSet(void)
 	 * since we are accessing parts of the mechList which could be
 	 * modified.
 	 */
-	if (k5_mutex_lock(&g_mechListLock) != 0)
-		return GSS_S_FAILURE;
+	k5_mutex_lock(&g_mechListLock);
 
 #if 0
 	/*
@@ -316,8 +309,7 @@ build_mechSet(void)
 	 * we need to lock the mech set so that no one else will
 	 * try to read it as we are re-creating it
 	 */
-	if (k5_mutex_lock(&g_mechSetLock) != 0)
-		return GSS_S_FAILURE;
+	k5_mutex_lock(&g_mechSetLock);
 
 	/* if the oid list already exists we must free it first */
 	free_mechSet();
@@ -335,8 +327,8 @@ build_mechSet(void)
 		g_mechSet.elements =
 			(gss_OID) calloc(count, sizeof (gss_OID_desc));
 		if (g_mechSet.elements == NULL) {
-			(void) k5_mutex_unlock(&g_mechSetLock);
-			(void) k5_mutex_unlock(&g_mechListLock);
+			k5_mutex_unlock(&g_mechSetLock);
+			k5_mutex_unlock(&g_mechListLock);
 			return (GSS_S_FAILURE);
 		}
 
@@ -364,8 +356,8 @@ build_mechSet(void)
 				free(g_mechSet.elements);
 				g_mechSet.count = 0;
 				g_mechSet.elements = NULL;
-				(void) k5_mutex_unlock(&g_mechSetLock);
-				(void) k5_mutex_unlock(&g_mechListLock);
+				k5_mutex_unlock(&g_mechSetLock);
+				k5_mutex_unlock(&g_mechListLock);
 				return (GSS_S_FAILURE);
 			}
 			g_OID_copy(curItem, mList->mech_type);
@@ -377,8 +369,8 @@ build_mechSet(void)
 #if 0
 	g_mechSetTime = fileInfo.st_mtime;
 #endif
-	(void) k5_mutex_unlock(&g_mechSetLock);
-	(void) k5_mutex_unlock(&g_mechListLock);
+	k5_mutex_unlock(&g_mechSetLock);
+	k5_mutex_unlock(&g_mechListLock);
 
 	return GSS_S_COMPLETE;
 }
@@ -402,19 +394,18 @@ const gss_OID oid;
 		return (NULL);
 
 	/* make sure we have fresh data */
-	if (k5_mutex_lock(&g_mechListLock) != 0)
-		return NULL;
+	k5_mutex_lock(&g_mechListLock);
 	updateMechList();
 
 	if ((aMech = searchMechList(oid)) == NULL ||
 		aMech->optionStr == NULL) {
-		(void) k5_mutex_unlock(&g_mechListLock);
+		k5_mutex_unlock(&g_mechListLock);
 		return (NULL);
 	}
 
 	if (aMech->optionStr)
 		modOptions = strdup(aMech->optionStr);
-	(void) k5_mutex_unlock(&g_mechListLock);
+	k5_mutex_unlock(&g_mechListLock);
 
 	return (modOptions);
 } /* gssint_get_modOptions */
@@ -924,8 +915,7 @@ gssint_select_mech_type(OM_uint32 *minor, gss_const_OID oid,
 	if (gssint_mechglue_initialize_library() != 0)
 		return GSS_S_FAILURE;
 
-	if (k5_mutex_lock(&g_mechListLock) != 0)
-		return GSS_S_FAILURE;
+	k5_mutex_lock(&g_mechListLock);
 
 	/* Read conf file at least once so that interposer plugins have a
 	 * chance of getting initialized. */
@@ -953,7 +943,7 @@ gssint_select_mech_type(OM_uint32 *minor, gss_const_OID oid,
 	status = GSS_S_BAD_MECH;
 
 done:
-	(void)k5_mutex_unlock(&g_mechListLock);
+	k5_mutex_unlock(&g_mechListLock);
 	return status;
 }
 
@@ -972,8 +962,7 @@ gssint_get_public_oid(gss_const_OID oid)
 	if (gssint_mechglue_initialize_library() != 0)
 		return GSS_C_NO_OID;
 
-	if (k5_mutex_lock(&g_mechListLock) != 0)
-		return GSS_C_NO_OID;
+	k5_mutex_lock(&g_mechListLock);
 
 	for (minfo = g_mechList; minfo != NULL; minfo = minfo->next) {
 		if (minfo->is_interposer)
@@ -986,7 +975,7 @@ gssint_get_public_oid(gss_const_OID oid)
 		}
 	}
 
-	(void)k5_mutex_unlock(&g_mechListLock);
+	k5_mutex_unlock(&g_mechListLock);
 	return public_oid;
 }
 
@@ -1045,8 +1034,7 @@ gssint_get_mechanism(gss_const_OID oid)
 	if (gssint_mechglue_initialize_library() != 0)
 		return (NULL);
 
-	if (k5_mutex_lock(&g_mechListLock) != 0)
-		return NULL;
+	k5_mutex_lock(&g_mechListLock);
 
 	/* Check if the mechanism is already loaded. */
 	aMech = g_mechList;
@@ -1054,11 +1042,11 @@ gssint_get_mechanism(gss_const_OID oid)
 		oid = aMech->mech_type;
 	while (aMech != NULL) {
 		if (g_OID_equal(aMech->mech_type, oid) && aMech->mech) {
-			(void)k5_mutex_unlock(&g_mechListLock);
+			k5_mutex_unlock(&g_mechListLock);
 			return aMech->mech;
 		} else if (aMech->int_mech_type != GSS_C_NO_OID &&
 			   g_OID_equal(aMech->int_mech_type, oid)) {
-			(void)k5_mutex_unlock(&g_mechListLock);
+			k5_mutex_unlock(&g_mechListLock);
 			return aMech->int_mech;
 		}
 		aMech = aMech->next;
@@ -1074,13 +1062,13 @@ gssint_get_mechanism(gss_const_OID oid)
 
 	/* is the mechanism present in the list ? */
 	if (aMech == NULL) {
-		(void) k5_mutex_unlock(&g_mechListLock);
+		k5_mutex_unlock(&g_mechListLock);
 		return ((gss_mechanism)NULL);
 	}
 
 	/* has another thread loaded the mech */
 	if (aMech->mech) {
-		(void) k5_mutex_unlock(&g_mechListLock);
+		k5_mutex_unlock(&g_mechListLock);
 		return (aMech->mech);
 	}
 
@@ -1092,7 +1080,7 @@ gssint_get_mechanism(gss_const_OID oid)
 		(void) syslog(LOG_INFO, "libgss dlopen(%s): %s\n",
 				aMech->uLibName, dlerror());
 #endif
-		(void) k5_mutex_unlock(&g_mechListLock);
+		k5_mutex_unlock(&g_mechListLock);
 		return ((gss_mechanism)NULL);
 	}
 
@@ -1111,13 +1099,13 @@ gssint_get_mechanism(gss_const_OID oid)
 		(void) syslog(LOG_INFO, "unable to initialize mechanism"
 				" library [%s]\n", aMech->uLibName);
 #endif
-		(void) k5_mutex_unlock(&g_mechListLock);
+		k5_mutex_unlock(&g_mechListLock);
 		return ((gss_mechanism)NULL);
 	}
 
 	aMech->dl_handle = dl;
 
-	(void) k5_mutex_unlock(&g_mechListLock);
+	k5_mutex_unlock(&g_mechListLock);
 	return (aMech->mech);
 } /* gssint_get_mechanism */
 
diff --git a/src/lib/kdb/kdb5.c b/src/lib/kdb/kdb5.c
index 779ce93..82dcfd2 100644
--- a/src/lib/kdb/kdb5.c
+++ b/src/lib/kdb/kdb5.c
@@ -89,7 +89,8 @@ kdb_lock_list()
     err = CALL_INIT_FUNCTION (kdb_init_lock_list);
     if (err)
         return err;
-    return k5_mutex_lock(&db_lock);
+    k5_mutex_lock(&db_lock);
+    return 0;
 }
 
 void
@@ -99,10 +100,10 @@ kdb_fini_lock_list()
         k5_mutex_destroy(&db_lock);
 }
 
-static int
+static void
 kdb_unlock_list()
 {
-    return k5_mutex_unlock(&db_lock);
+    k5_mutex_unlock(&db_lock);
 }
 
 /* Return true if the ulog is mapped in the master role. */
diff --git a/src/lib/krb5/ccache/cc-int.h b/src/lib/krb5/ccache/cc-int.h
index c29fbec..272425e 100644
--- a/src/lib/krb5/ccache/cc-int.h
+++ b/src/lib/krb5/ccache/cc-int.h
@@ -98,10 +98,10 @@ k5_cc_mutex_assert_locked(krb5_context context, k5_cc_mutex *m);
 void
 k5_cc_mutex_assert_unlocked(krb5_context context, k5_cc_mutex *m);
 
-krb5_error_code
+void
 k5_cc_mutex_lock(krb5_context context, k5_cc_mutex *m);
 
-krb5_error_code
+void
 k5_cc_mutex_unlock(krb5_context context, k5_cc_mutex *m);
 
 extern k5_cc_mutex krb5int_mcc_mutex;
@@ -116,10 +116,10 @@ extern krb5_error_code KRB5_CALLCONV krb5_stdccv3_context_unlock
 (krb5_context context);
 #endif
 
-krb5_error_code
+void
 k5_cc_mutex_force_unlock(k5_cc_mutex *m);
 
-krb5_error_code
+void
 k5_cccol_force_unlock(void);
 
 krb5_error_code
diff --git a/src/lib/krb5/ccache/cc_file.c b/src/lib/krb5/ccache/cc_file.c
index 24b36b8..3ba1318 100644
--- a/src/lib/krb5/ccache/cc_file.c
+++ b/src/lib/krb5/ccache/cc_file.c
@@ -1440,9 +1440,7 @@ krb5_fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
     krb5_error_code kret = 0;
     int reti = 0;
 
-    kret = k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
 
     MAYBE_OPEN(context, id, FCC_OPEN_AND_ERASE);
 
@@ -1475,12 +1473,9 @@ krb5_fcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
  */
 static krb5_error_code dereference(krb5_context context, krb5_fcc_data *data)
 {
-    krb5_error_code kerr;
     struct fcc_set **fccsp;
 
-    kerr = k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
-    if (kerr)
-        return kerr;
+    k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
     for (fccsp = &fccs; *fccsp != NULL; fccsp = &(*fccsp)->next)
         if ((*fccsp)->data == data)
             break;
@@ -1498,9 +1493,7 @@ static krb5_error_code dereference(krb5_context context, krb5_fcc_data *data)
         free(data->filename);
         zap(data->buf, sizeof(data->buf));
         if (data->file >= 0) {
-            kerr = k5_cc_mutex_lock(context, &data->lock);
-            if (kerr)
-                return kerr;
+            k5_cc_mutex_lock(context, &data->lock);
             krb5_fcc_close_file(context, data);
             k5_cc_mutex_unlock(context, &data->lock);
         }
@@ -1546,9 +1539,7 @@ krb5_fcc_destroy(krb5_context context, krb5_ccache id)
     unsigned int wlen;
     char zeros[BUFSIZ];
 
-    kret = k5_cc_mutex_lock(context, &data->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &data->lock);
 
     if (OPENCLOSE(id)) {
         invalidate_cache(data);
@@ -1693,9 +1684,7 @@ krb5_fcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
     krb5_fcc_data *data;
     struct fcc_set *setptr;
 
-    kret = k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
     for (setptr = fccs; setptr; setptr = setptr->next) {
         if (!strcmp(setptr->data->filename, residual))
             break;
@@ -1705,11 +1694,7 @@ krb5_fcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
         assert(setptr->refcount != 0);
         setptr->refcount++;
         assert(setptr->refcount != 0);
-        kret = k5_cc_mutex_lock(context, &data->lock);
-        if (kret) {
-            k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
-            return kret;
-        }
+        k5_cc_mutex_lock(context, &data->lock);
         k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
     } else {
         data = malloc(sizeof(krb5_fcc_data));
@@ -1730,14 +1715,7 @@ krb5_fcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
             free(data);
             return kret;
         }
-        kret = k5_cc_mutex_lock(context, &data->lock);
-        if (kret) {
-            k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
-            k5_cc_mutex_destroy(&data->lock);
-            free(data->filename);
-            free(data);
-            return kret;
-        }
+        k5_cc_mutex_lock(context, &data->lock);
         /* data->version,mode filled in for real later */
         data->version = data->mode = 0;
         data->flags = KRB5_TC_OPENCLOSE;
@@ -1798,9 +1776,7 @@ krb5_fcc_start_seq_get(krb5_context context, krb5_ccache id,
     krb5_error_code kret = KRB5_OK;
     krb5_fcc_data *data = (krb5_fcc_data *)id->data;
 
-    kret = k5_cc_mutex_lock(context, &data->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &data->lock);
 
     fcursor = (krb5_fcc_cursor *) malloc(sizeof(krb5_fcc_cursor));
     if (fcursor == NULL) {
@@ -1869,9 +1845,7 @@ krb5_fcc_next_cred(krb5_context context, krb5_ccache id, krb5_cc_cursor *cursor,
     krb5_octet octet;
     krb5_fcc_data *d = (krb5_fcc_data *) id->data;
 
-    kret = k5_cc_mutex_lock(context, &d->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     memset(creds, 0, sizeof(*creds));
     MAYBE_OPEN(context, id, FCC_OPEN_RDONLY);
@@ -1960,9 +1934,7 @@ krb5int_fcc_new_unique(krb5_context context, char *template, krb5_ccache *id)
     struct fcc_set *setptr;
 
     /* Set master lock */
-    kret = k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
 
     ret = mkstemp(template);
     if (ret == -1) {
@@ -1998,16 +1970,7 @@ krb5int_fcc_new_unique(krb5_context context, char *template, krb5_ccache *id)
         unlink(template);
         return kret;
     }
-    kret = k5_cc_mutex_lock(context, &data->lock);
-    if (kret) {
-        k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
-        k5_cc_mutex_destroy(&data->lock);
-        free(data->filename);
-        free(data);
-        close(ret);
-        unlink(template);
-        return kret;
-    }
+    k5_cc_mutex_lock(context, &data->lock);
 
     /*
      * The file is initially closed at the end of this call...
@@ -2156,9 +2119,7 @@ krb5_fcc_get_principal(krb5_context context, krb5_ccache id, krb5_principal *pri
 {
     krb5_error_code kret = KRB5_OK;
 
-    kret = k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
 
     MAYBE_OPEN(context, id, FCC_OPEN_RDONLY);
 
@@ -2199,9 +2160,7 @@ krb5_fcc_store(krb5_context context, krb5_ccache id, krb5_creds *creds)
 #define TCHECK(ret) if (ret != KRB5_OK) goto lose;
     krb5_error_code ret;
 
-    ret = k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
-    if (ret)
-        return ret;
+    k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
 
     /* Make sure we are writing to the end of the file */
     MAYBE_OPEN(context, id, FCC_OPEN_RDWR);
@@ -2272,9 +2231,7 @@ krb5_fcc_set_flags(krb5_context context, krb5_ccache id, krb5_flags flags)
 {
     krb5_error_code ret = KRB5_OK;
 
-    ret = k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
-    if (ret)
-        return ret;
+    k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
 
     /* XXX This should check for illegal combinations, if any.. */
     if (flags & KRB5_TC_OPENCLOSE) {
@@ -2308,14 +2265,10 @@ krb5_fcc_set_flags(krb5_context context, krb5_ccache id, krb5_flags flags)
 static krb5_error_code KRB5_CALLCONV
 krb5_fcc_get_flags(krb5_context context, krb5_ccache id, krb5_flags *flags)
 {
-    krb5_error_code ret = KRB5_OK;
-
-    ret = k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
-    if (ret)
-        return ret;
+    k5_cc_mutex_lock(context, &((krb5_fcc_data *) id->data)->lock);
     *flags = ((krb5_fcc_data *) id->data)->flags;
     k5_cc_mutex_unlock(context, &((krb5_fcc_data *) id->data)->lock);
-    return ret;
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
@@ -2415,19 +2368,17 @@ krb5_fcc_last_change_time(krb5_context context, krb5_ccache id,
 static krb5_error_code KRB5_CALLCONV
 krb5_fcc_lock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_fcc_data *data = (krb5_fcc_data *) id->data;
-    ret = k5_cc_mutex_lock(context, &data->lock);
-    return ret;
+    k5_cc_mutex_lock(context, &data->lock);
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
 krb5_fcc_unlock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_fcc_data *data = (krb5_fcc_data *) id->data;
-    ret = k5_cc_mutex_unlock(context, &data->lock);
-    return ret;
+    k5_cc_mutex_unlock(context, &data->lock);
+    return 0;
 }
 
 static krb5_error_code
@@ -2441,10 +2392,7 @@ krb5_fcc_data_last_change_time(krb5_context context, krb5_fcc_data *data,
 
     *change_time = 0;
 
-    kret = k5_cc_mutex_lock(context, &data->lock);
-    if (kret) {
-        return kret;
-    }
+    k5_cc_mutex_lock(context, &data->lock);
 
     ret = stat(data->filename, &buf);
     if (ret == -1) {
diff --git a/src/lib/krb5/ccache/cc_keyring.c b/src/lib/krb5/ccache/cc_keyring.c
index 20b275c..bbe2a2e 100644
--- a/src/lib/krb5/ccache/cc_keyring.c
+++ b/src/lib/krb5/ccache/cc_keyring.c
@@ -392,9 +392,7 @@ krb5_krcc_initialize(krb5_context context, krb5_ccache id,
 
     DEBUG_PRINT(("krb5_krcc_initialize: entered\n"));
 
-    kret = k5_cc_mutex_lock(context, &((krb5_krcc_data *) id->data)->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &((krb5_krcc_data *) id->data)->lock);
 
     kret = krb5_krcc_clearcache(context, id);
     if (kret != KRB5_OK)
@@ -484,7 +482,7 @@ krb5_krcc_clearcache(krb5_context context, krb5_ccache id)
 static krb5_error_code KRB5_CALLCONV
 krb5_krcc_destroy(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code kret;
+    krb5_error_code kret = 0;
     krb5_krcc_data *d;
     int     res;
 
@@ -492,9 +490,7 @@ krb5_krcc_destroy(krb5_context context, krb5_ccache id)
 
     d = (krb5_krcc_data *) id->data;
 
-    kret = k5_cc_mutex_lock(context, &d->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     krb5_krcc_clearcache(context, id);
     free(d->name);
@@ -513,7 +509,7 @@ cleanup:
 
     krb5_change_cache();
 
-    return KRB5_OK;
+    return kret;
 }
 
 
@@ -653,7 +649,6 @@ krb5_krcc_start_seq_get(krb5_context context, krb5_ccache id,
                         krb5_cc_cursor * cursor)
 {
     krb5_krcc_cursor krcursor;
-    krb5_error_code kret;
     krb5_krcc_data *d;
     unsigned int size;
     int     res;
@@ -661,9 +656,7 @@ krb5_krcc_start_seq_get(krb5_context context, krb5_ccache id,
     DEBUG_PRINT(("krb5_krcc_start_seq_get: entered\n"));
 
     d = id->data;
-    kret = k5_cc_mutex_lock(context, &d->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     /*
      * Determine how many keys currently exist and update numkeys.
@@ -862,11 +855,7 @@ krb5_krcc_generate_new(krb5_context context, krb5_ccache * id)
 
     lid->ops = &krb5_krcc_ops;
 
-    kret = k5_cc_mutex_lock(context, &krb5int_krcc_mutex);
-    if (kret) {
-        free(lid);
-        return kret;
-    }
+    k5_cc_mutex_lock(context, &krb5int_krcc_mutex);
 
 /* XXX These values are platform-specific and should not be here! */
 /* XXX There is a bug in FC5 where these are not included in errno.h  */
@@ -1028,9 +1017,7 @@ krb5_krcc_store(krb5_context context, krb5_ccache id, krb5_creds * creds)
 
     DEBUG_PRINT(("krb5_krcc_store: entered\n"));
 
-    kret = k5_cc_mutex_lock(context, &d->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     /* Get the service principal name and use it as the key name */
     kret = krb5_unparse_name(context, creds->server, &keyname);
@@ -1073,36 +1060,30 @@ static krb5_error_code KRB5_CALLCONV
 krb5_krcc_last_change_time(krb5_context context, krb5_ccache id,
                            krb5_timestamp *change_time)
 {
-    krb5_error_code ret = 0;
     krb5_krcc_data *data = (krb5_krcc_data *) id->data;
 
-    *change_time = 0;
-
-    ret = k5_cc_mutex_lock(context, &data->lock);
-    if (!ret) {
-        *change_time = data->changetime;
-        k5_cc_mutex_unlock(context, &data->lock);
-    }
-
-    return ret;
+    k5_cc_mutex_lock(context, &data->lock);
+    *change_time = data->changetime;
+    k5_cc_mutex_unlock(context, &data->lock);
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
 krb5_krcc_lock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_krcc_data *data = (krb5_krcc_data *) id->data;
-    ret = k5_cc_mutex_lock(context, &data->lock);
-    return ret;
+
+    k5_cc_mutex_lock(context, &data->lock);
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
 krb5_krcc_unlock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_krcc_data *data = (krb5_krcc_data *) id->data;
-    ret = k5_cc_mutex_unlock(context, &data->lock);
-    return ret;
+
+    k5_cc_mutex_unlock(context, &data->lock);
+    return 0;
 }
 
 
@@ -1172,9 +1153,7 @@ krb5_krcc_retrieve_principal(krb5_context context, krb5_ccache id,
     int     psize;
     krb5_krcc_bc bc;
 
-    kret = k5_cc_mutex_lock(context, &d->lock);
-    if (kret)
-        return kret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     if (!d->princ_id) {
         princ = 0L;
diff --git a/src/lib/krb5/ccache/cc_memory.c b/src/lib/krb5/ccache/cc_memory.c
index b774251..e1cc638 100644
--- a/src/lib/krb5/ccache/cc_memory.c
+++ b/src/lib/krb5/ccache/cc_memory.c
@@ -153,9 +153,7 @@ krb5_mcc_initialize(krb5_context context, krb5_ccache id, krb5_principal princ)
     krb5_mcc_data *d;
 
     d = (krb5_mcc_data *)id->data;
-    ret = k5_cc_mutex_lock(context, &d->lock);
-    if (ret)
-        return ret;
+    k5_cc_mutex_lock(context, &d->lock);
 
     krb5_mcc_free(context, id);
 
@@ -220,11 +218,8 @@ krb5_mcc_destroy(krb5_context context, krb5_ccache id)
 {
     krb5_mcc_list_node **curr, *node;
     krb5_mcc_data *d;
-    krb5_error_code err;
 
-    err = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (err)
-        return err;
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
 
     d = (krb5_mcc_data *)id->data;
     for (curr = &mcc_head; *curr; curr = &(*curr)->next) {
@@ -237,9 +232,7 @@ krb5_mcc_destroy(krb5_context context, krb5_ccache id)
     }
     k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
 
-    err = k5_cc_mutex_lock(context, &d->lock);
-    if (err)
-        return err;
+    k5_cc_mutex_lock(context, &d->lock);
 
     krb5_mcc_free(context, id);
     free(d->name);
@@ -282,9 +275,7 @@ krb5_mcc_resolve (krb5_context context, krb5_ccache *id, const char *residual)
     krb5_error_code err;
     krb5_mcc_data *d;
 
-    err = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (err)
-        return err;
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
     for (ptr = mcc_head; ptr; ptr=ptr->next)
         if (!strcmp(ptr->cache->name, residual))
             break;
@@ -336,13 +327,10 @@ krb5_mcc_start_seq_get(krb5_context context, krb5_ccache id,
                        krb5_cc_cursor *cursor)
 {
     krb5_mcc_cursor mcursor;
-    krb5_error_code err;
     krb5_mcc_data *d;
 
     d = id->data;
-    err = k5_cc_mutex_lock(context, &d->lock);
-    if (err)
-        return err;
+    k5_cc_mutex_lock(context, &d->lock);
     mcursor = d->link;
     k5_cc_mutex_unlock(context, &d->lock);
     *cursor = (krb5_cc_cursor) mcursor;
@@ -491,11 +479,7 @@ krb5_mcc_generate_new (krb5_context context, krb5_ccache *id)
 
     lid->ops = &krb5_mcc_ops;
 
-    err = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (err) {
-        free(lid);
-        return err;
-    }
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
 
     /* Check for uniqueness with mutex locked to avoid race conditions */
     while (1) {
@@ -674,9 +658,7 @@ krb5_mcc_store(krb5_context ctx, krb5_ccache id, krb5_creds *creds)
     err = krb5_copy_creds(ctx, creds, &new_node->creds);
     if (err)
         goto cleanup;
-    err = k5_cc_mutex_lock(ctx, &mptr->lock);
-    if (err)
-        goto cleanup;
+    k5_cc_mutex_lock(ctx, &mptr->lock);
     new_node->next = mptr->link;
     mptr->link = new_node;
     update_mcc_change_time(mptr);
@@ -692,7 +674,6 @@ krb5_mcc_ptcursor_new(
     krb5_context context,
     krb5_cc_ptcursor *cursor)
 {
-    krb5_error_code ret = 0;
     krb5_cc_ptcursor n = NULL;
     struct krb5_mcc_ptcursor_data *cdata = NULL;
 
@@ -704,24 +685,15 @@ krb5_mcc_ptcursor_new(
     n->ops = &krb5_mcc_ops;
     cdata = malloc(sizeof(struct krb5_mcc_ptcursor_data));
     if (cdata == NULL) {
-        ret = ENOMEM;
-        goto errout;
+        free(n);
+        return ENOMEM;
     }
     n->data = cdata;
-    ret = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (ret)
-        goto errout;
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
     cdata->cur = mcc_head;
-    ret = k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
-    if (ret)
-        goto errout;
-
-errout:
-    if (ret) {
-        krb5_mcc_ptcursor_free(context, &n);
-    }
+    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
     *cursor = n;
-    return ret;
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
@@ -730,7 +702,6 @@ krb5_mcc_ptcursor_next(
     krb5_cc_ptcursor cursor,
     krb5_ccache *ccache)
 {
-    krb5_error_code ret = 0;
     struct krb5_mcc_ptcursor_data *cdata = NULL;
 
     *ccache = NULL;
@@ -744,19 +715,10 @@ krb5_mcc_ptcursor_next(
 
     (*ccache)->ops = &krb5_mcc_ops;
     (*ccache)->data = cdata->cur->cache;
-    ret = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (ret)
-        goto errout;
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
     cdata->cur = cdata->cur->next;
-    ret = k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
-    if (ret)
-        goto errout;
-errout:
-    if (ret && *ccache != NULL) {
-        free(*ccache);
-        *ccache = NULL;
-    }
-    return ret;
+    k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
@@ -779,18 +741,12 @@ krb5_mcc_last_change_time(
     krb5_ccache id,
     krb5_timestamp *change_time)
 {
-    krb5_error_code ret = 0;
     krb5_mcc_data *data = (krb5_mcc_data *) id->data;
 
-    *change_time = 0;
-
-    ret = k5_cc_mutex_lock(context, &data->lock);
-    if (!ret) {
-        *change_time = data->changetime;
-        k5_cc_mutex_unlock(context, &data->lock);
-    }
-
-    return ret;
+    k5_cc_mutex_lock(context, &data->lock);
+    *change_time = data->changetime;
+    k5_cc_mutex_unlock(context, &data->lock);
+    return 0;
 }
 
 /*
@@ -809,19 +765,19 @@ update_mcc_change_time(krb5_mcc_data *d)
 static krb5_error_code KRB5_CALLCONV
 krb5_mcc_lock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_mcc_data *data = (krb5_mcc_data *) id->data;
-    ret = k5_cc_mutex_lock(context, &data->lock);
-    return ret;
+
+    k5_cc_mutex_lock(context, &data->lock);
+    return 0;
 }
 
 static krb5_error_code KRB5_CALLCONV
 krb5_mcc_unlock(krb5_context context, krb5_ccache id)
 {
-    krb5_error_code ret = 0;
     krb5_mcc_data *data = (krb5_mcc_data *) id->data;
-    ret = k5_cc_mutex_unlock(context, &data->lock);
-    return ret;
+
+    k5_cc_mutex_unlock(context, &data->lock);
+    return 0;
 }
 
 const krb5_cc_ops krb5_mcc_ops = {
diff --git a/src/lib/krb5/ccache/ccbase.c b/src/lib/krb5/ccache/ccbase.c
index 370c943..191a97a 100644
--- a/src/lib/krb5/ccache/ccbase.c
+++ b/src/lib/krb5/ccache/ccbase.c
@@ -151,11 +151,8 @@ krb5_cc_register(krb5_context context, const krb5_cc_ops *ops,
                  krb5_boolean override)
 {
     struct krb5_cc_typelist *t;
-    krb5_error_code err;
 
-    err = k5_mutex_lock(&cc_typelist_lock);
-    if (err)
-        return err;
+    k5_mutex_lock(&cc_typelist_lock);
     for (t = cc_typehead;t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
         ;
     if (t) {
@@ -254,13 +251,9 @@ krb5int_cc_getops(krb5_context context,
                   const char *pfx,
                   const krb5_cc_ops **ops)
 {
-    krb5_error_code err;
     struct krb5_cc_typelist *tlist;
 
-    err = k5_mutex_lock(&cc_typelist_lock);
-    if (err)
-        return err;
-
+    k5_mutex_lock(&cc_typelist_lock);
     for (tlist = cc_typehead; tlist; tlist = tlist->next) {
         if (strcmp (tlist->ops->prefix, pfx) == 0) {
             *ops = tlist->ops;
@@ -312,7 +305,6 @@ krb5_cc_new_unique(
 krb5_error_code
 krb5int_cc_typecursor_new(krb5_context context, krb5_cc_typecursor *t)
 {
-    krb5_error_code err = 0;
     krb5_cc_typecursor n = NULL;
 
     *t = NULL;
@@ -320,19 +312,11 @@ krb5int_cc_typecursor_new(krb5_context context, krb5_cc_typecursor *t)
     if (n == NULL)
         return ENOMEM;
 
-    err = k5_mutex_lock(&cc_typelist_lock);
-    if (err)
-        goto errout;
+    k5_mutex_lock(&cc_typelist_lock);
     n->tptr = cc_typehead;
-    err = k5_mutex_unlock(&cc_typelist_lock);
-    if (err)
-        goto errout;
-
+    k5_mutex_unlock(&cc_typelist_lock);
     *t = n;
-errout:
-    if (err)
-        free(n);
-    return err;
+    return 0;
 }
 
 krb5_error_code
@@ -340,23 +324,15 @@ krb5int_cc_typecursor_next(krb5_context context,
                            krb5_cc_typecursor t,
                            const krb5_cc_ops **ops)
 {
-    krb5_error_code err = 0;
-
     *ops = NULL;
     if (t->tptr == NULL)
         return 0;
 
-    err = k5_mutex_lock(&cc_typelist_lock);
-    if (err)
-        goto errout;
+    k5_mutex_lock(&cc_typelist_lock);
     *ops = t->tptr->ops;
     t->tptr = t->tptr->next;
-    err = k5_mutex_unlock(&cc_typelist_lock);
-    if (err)
-        goto errout;
-
-errout:
-    return err;
+    k5_mutex_unlock(&cc_typelist_lock);
+    return 0;
 }
 
 krb5_error_code
@@ -470,15 +446,13 @@ k5_cc_mutex_assert_unlocked(krb5_context context, k5_cc_mutex *m)
     k5_assert_unlocked(&m->lock);
 }
 
-krb5_error_code
+void
 k5_cc_mutex_lock(krb5_context context, k5_cc_mutex *m)
 {
-    krb5_error_code ret = 0;
-
     /* not locked or already locked by another context */
     if (m->owner != context) {
         /* acquire lock, blocking until available */
-        ret = k5_mutex_lock(&m->lock);
+        k5_mutex_lock(&m->lock);
         m->owner = context;
         m->refcount = 1;
     }
@@ -486,17 +460,14 @@ k5_cc_mutex_lock(krb5_context context, k5_cc_mutex *m)
     else {
         m->refcount++;
     }
-    return ret;
 }
 
-krb5_error_code
+void
 k5_cc_mutex_unlock(krb5_context context, k5_cc_mutex *m)
 {
-    krb5_error_code ret = 0;
-
     /* verify owner and sanity check refcount */
     if ((m->owner != context) || (m->refcount < 1)) {
-        return ret;
+        return;
     }
     /* decrement & unlock when count reaches zero */
     m->refcount--;
@@ -504,21 +475,17 @@ k5_cc_mutex_unlock(krb5_context context, k5_cc_mutex *m)
         m->owner = NULL;
         k5_mutex_unlock(&m->lock);
     }
-    return ret;
 }
 
 /* necessary to make reentrant locks play nice with krb5int_cc_finalize */
-krb5_error_code
+void
 k5_cc_mutex_force_unlock(k5_cc_mutex *m)
 {
-    krb5_error_code ret = 0;
-
     m->refcount = 0;
     m->owner = NULL;
     if (m->refcount > 0) {
         k5_mutex_unlock(&m->lock);
     }
-    return ret;
 }
 
 /*
@@ -530,34 +497,16 @@ krb5_cccol_lock(krb5_context context)
 {
     krb5_error_code ret = 0;
 
-    ret = k5_cc_mutex_lock(context, &cccol_lock);
-    if (ret) {
-        return ret;
-    }
-    ret = k5_mutex_lock(&cc_typelist_lock);
-    if (ret) {
-        k5_cc_mutex_unlock(context, &cccol_lock);
-        return ret;
-    }
-    ret = k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
-    if (ret) {
-        k5_mutex_unlock(&cc_typelist_lock);
-        k5_cc_mutex_unlock(context, &cccol_lock);
-        return ret;
-    }
-    ret = k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
-    if (ret) {
-        k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
-        k5_mutex_unlock(&cc_typelist_lock);
-        k5_cc_mutex_unlock(context, &cccol_lock);
-        return ret;
-    }
+    k5_cc_mutex_lock(context, &cccol_lock);
+    k5_mutex_lock(&cc_typelist_lock);
+    k5_cc_mutex_lock(context, &krb5int_cc_file_mutex);
+    k5_cc_mutex_lock(context, &krb5int_mcc_mutex);
+#ifdef USE_KEYRING_CCACHE
+    k5_cc_mutex_lock(context, &krb5int_krcc_mutex);
+#endif
 #ifdef USE_CCAPI_V3
     ret = krb5_stdccv3_context_lock(context);
 #endif
-#ifdef USE_KEYRING_CCACHE
-    ret = k5_cc_mutex_lock(context, &krb5int_krcc_mutex);
-#endif
     if (ret) {
         k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
         k5_cc_mutex_unlock(context, &krb5int_cc_file_mutex);
@@ -577,20 +526,16 @@ krb5_cccol_unlock(krb5_context context)
     /* sanity check */
     k5_cc_mutex_assert_locked(context, &cccol_lock);
 
-    ret = k5_mutex_lock(&cc_typelist_lock);
-    if (ret) {
-        k5_cc_mutex_unlock(context, &cccol_lock);
-        return ret;
-    }
+    k5_mutex_lock(&cc_typelist_lock);
 
     /* unlock each type in the opposite order */
+#ifdef USE_CCAPI_V3
+    krb5_stdccv3_context_unlock(context);
+#endif
 #ifdef USE_KEYRING_CCACHE
     k5_cc_mutex_assert_locked(context, &krb5int_krcc_mutex);
     k5_cc_mutex_unlock(context, &krb5int_krcc_mutex);
 #endif
-#ifdef USE_CCAPI_V3
-    krb5_stdccv3_context_unlock(context);
-#endif
     k5_cc_mutex_assert_locked(context, &krb5int_mcc_mutex);
     k5_cc_mutex_unlock(context, &krb5int_mcc_mutex);
     k5_cc_mutex_assert_locked(context, &krb5int_cc_file_mutex);
@@ -604,23 +549,15 @@ krb5_cccol_unlock(krb5_context context)
 }
 
 /* necessary to make reentrant locks play nice with krb5int_cc_finalize */
-krb5_error_code
+void
 k5_cccol_force_unlock()
 {
-    krb5_error_code ret = 0;
-
     /* sanity check */
     if ((&cccol_lock)->refcount == 0) {
-        return 0;
+        return;
     }
 
-    ret = k5_mutex_lock(&cc_typelist_lock);
-    if (ret) {
-        (&cccol_lock)->refcount = 0;
-        (&cccol_lock)->owner = NULL;
-        k5_mutex_unlock(&(&cccol_lock)->lock);
-        return ret;
-    }
+    k5_mutex_lock(&cc_typelist_lock);
 
     /* unlock each type in the opposite order */
 #ifdef USE_KEYRING_CCACHE
@@ -634,6 +571,4 @@ k5_cccol_force_unlock()
 
     k5_mutex_unlock(&cc_typelist_lock);
     k5_cc_mutex_force_unlock(&cccol_lock);
-
-    return ret;
 }
diff --git a/src/lib/krb5/keytab/kt_file.c b/src/lib/krb5/keytab/kt_file.c
index 8dcf787..82d3c41 100644
--- a/src/lib/krb5/keytab/kt_file.c
+++ b/src/lib/krb5/keytab/kt_file.c
@@ -272,9 +272,7 @@ krb5_ktfile_get_entry(krb5_context context, krb5_keytab id,
     int was_open;
     char *princname;
 
-    kerror = KTLOCK(id);
-    if (kerror)
-        return kerror;
+    KTLOCK(id);
 
     if (KTFILEP(id) != NULL) {
         was_open = 1;
@@ -452,9 +450,7 @@ krb5_ktfile_start_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *
     krb5_error_code retval;
     long *fileoff;
 
-    retval = KTLOCK(id);
-    if (retval)
-        return retval;
+    KTLOCK(id);
 
     if (KTITERS(id) == 0) {
         if ((retval = krb5_ktfileint_openr(context, id))) {
@@ -496,9 +492,7 @@ krb5_ktfile_get_next(krb5_context context, krb5_keytab id, krb5_keytab_entry *en
     krb5_keytab_entry cur_entry;
     krb5_error_code kerror;
 
-    kerror = KTLOCK(id);
-    if (kerror)
-        return kerror;
+    KTLOCK(id);
     if (KTFILEP(id) == NULL) {
         KTUNLOCK(id);
         return KRB5_KT_IOERR;
@@ -527,9 +521,7 @@ krb5_ktfile_end_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursor
     krb5_error_code kerror;
 
     free(*cursor);
-    kerror = KTLOCK(id);
-    if (kerror)
-        return kerror;
+    KTLOCK(id);
     KTITERS(id)--;
     if (KTFILEP(id) != NULL && KTITERS(id) == 0)
         kerror = krb5_ktfileint_close(context, id);
@@ -817,9 +809,7 @@ krb5_ktfile_add(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry)
 {
     krb5_error_code retval;
 
-    retval = KTLOCK(id);
-    if (retval)
-        return retval;
+    KTLOCK(id);
     if (KTFILEP(id)) {
         /* Iterator(s) active -- no changes.  */
         KTUNLOCK(id);
@@ -853,9 +843,7 @@ krb5_ktfile_remove(krb5_context context, krb5_keytab id, krb5_keytab_entry *entr
     krb5_error_code     kerror;
     krb5_int32          delete_point;
 
-    kerror = KTLOCK(id);
-    if (kerror)
-        return kerror;
+    KTLOCK(id);
     if (KTFILEP(id)) {
         /* Iterator(s) active -- no changes.  */
         KTUNLOCK(id);
diff --git a/src/lib/krb5/keytab/kt_memory.c b/src/lib/krb5/keytab/kt_memory.c
index 5ec304a..e89fdcb 100644
--- a/src/lib/krb5/keytab/kt_memory.c
+++ b/src/lib/krb5/keytab/kt_memory.c
@@ -249,9 +249,7 @@ krb5_mkt_resolve(krb5_context context, const char *name, krb5_keytab *id)
     *id = NULL;
 
     /* First determine if a memory keytab of this name already exists */
-    err = KTGLOCK;
-    if (err)
-        return err;
+    KTGLOCK;
 
     for (list = krb5int_mkt_list; list; list = list->next) {
         if (strcmp(name,KTNAME(list->keytab)) == 0)
@@ -271,9 +269,7 @@ krb5_mkt_resolve(krb5_context context, const char *name, krb5_keytab *id)
     }
 
     /* Increment the reference count on the keytab we found or created. */
-    err = KTLOCK(list->keytab);
-    if (err)
-        goto done;
+    KTLOCK(list->keytab);
     KTREFCNT(list->keytab)++;
     KTUNLOCK(list->keytab);
     *id = list->keytab;
@@ -301,9 +297,7 @@ krb5_mkt_close(krb5_context context, krb5_keytab id)
     krb5_error_code err = 0;
 
     /* First determine if a memory keytab of this name already exists */
-    err = KTGLOCK;
-    if (err)
-        return(err);
+    KTGLOCK;
 
     for (listp = &krb5int_mkt_list; *listp; listp = &((*listp)->next))
     {
@@ -320,10 +314,7 @@ krb5_mkt_close(krb5_context context, krb5_keytab id)
     }
 
     /* reduce the refcount and return */
-    err = KTLOCK(id);
-    if (err)
-        goto done;
-
+    KTLOCK(id);
     KTREFCNT(id)--;
     KTUNLOCK(id);
 
@@ -388,9 +379,7 @@ krb5_mkt_get_entry(krb5_context context, krb5_keytab id,
     int found_wrong_kvno = 0;
     krb5_boolean similar = 0;
 
-    err = KTLOCK(id);
-    if (err)
-        return err;
+    KTLOCK(id);
 
     for (cursor = KTLINK(id); cursor && cursor->entry; cursor = cursor->next) {
         entry = cursor->entry;
@@ -480,12 +469,7 @@ krb5_mkt_get_name(krb5_context context, krb5_keytab id, char *name, unsigned int
 krb5_error_code KRB5_CALLCONV
 krb5_mkt_start_seq_get(krb5_context context, krb5_keytab id, krb5_kt_cursor *cursorp)
 {
-    krb5_error_code err = 0;
-
-    err = KTLOCK(id);
-    if (err)
-        return(err);
-
+    KTLOCK(id);
     *cursorp = (krb5_kt_cursor)KTLINK(id);
     KTUNLOCK(id);
 
@@ -502,9 +486,7 @@ krb5_mkt_get_next(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry
     krb5_mkt_cursor mkt_cursor = (krb5_mkt_cursor)*cursor;
     krb5_error_code err = 0;
 
-    err = KTLOCK(id);
-    if (err)
-        return err;
+    KTLOCK(id);
 
     if (mkt_cursor == NULL) {
         KTUNLOCK(id);
@@ -548,9 +530,7 @@ krb5_mkt_add(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry)
     krb5_error_code err = 0;
     krb5_mkt_cursor cursor;
 
-    err = KTLOCK(id);
-    if (err)
-        return err;
+    KTLOCK(id);
 
     cursor = (krb5_mkt_cursor)malloc(sizeof(krb5_mkt_link));
     if (cursor == NULL) {
@@ -605,9 +585,7 @@ krb5_mkt_remove(krb5_context context, krb5_keytab id, krb5_keytab_entry *entry)
     krb5_mkt_cursor *pcursor, next;
     krb5_error_code err = 0;
 
-    err = KTLOCK(id);
-    if (err)
-        return err;
+    KTLOCK(id);
 
     if ( KTLINK(id) == NULL ) {
         err = KRB5_KT_NOTFOUND;
diff --git a/src/lib/krb5/keytab/ktbase.c b/src/lib/krb5/keytab/ktbase.c
index 848b047..0d39b29 100644
--- a/src/lib/krb5/keytab/ktbase.c
+++ b/src/lib/krb5/keytab/ktbase.c
@@ -123,11 +123,8 @@ krb5_kt_register(krb5_context context, const krb5_kt_ops *ops)
 {
     const struct krb5_kt_typelist *t;
     struct krb5_kt_typelist *newt;
-    krb5_error_code err;
 
-    err = k5_mutex_lock(&kt_typehead_lock);
-    if (err)
-        return err;
+    k5_mutex_lock(&kt_typehead_lock);
     for (t = kt_typehead; t && strcmp(t->ops->prefix,ops->prefix);t = t->next)
         ;
     if (t) {
@@ -195,9 +192,7 @@ krb5_kt_resolve (krb5_context context, const char *name, krb5_keytab *ktid)
 
     *ktid = (krb5_keytab) 0;
 
-    err = k5_mutex_lock(&kt_typehead_lock);
-    if (err)
-        goto cleanup;
+    k5_mutex_lock(&kt_typehead_lock);
     tlist = kt_typehead;
     /* Don't need to hold the lock, since entries are never modified
        or removed once they're in the list.  Just need to protect
diff --git a/src/lib/krb5/os/c_ustime.c b/src/lib/krb5/os/c_ustime.c
index d374b13..871d721 100644
--- a/src/lib/krb5/os/c_ustime.c
+++ b/src/lib/krb5/os/c_ustime.c
@@ -88,9 +88,7 @@ krb5_crypto_us_timeofday(krb5_int32 *seconds, krb5_int32 *microseconds)
        different threads getting the same value for time, which may be
        a technical violation of spec. */
 
-    err = k5_mutex_lock(&krb5int_us_time_mutex);
-    if (err)
-        return err;
+    k5_mutex_lock(&krb5int_us_time_mutex);
     /* Just guessing: If the number of seconds hasn't changed, yet the
        microseconds are moving backwards, we probably just got a third
        instance of returning the same clock value from the system, so
diff --git a/src/lib/krb5/rcache/rc_base.c b/src/lib/krb5/rcache/rc_base.c
index 5097271..2fc96c5 100644
--- a/src/lib/krb5/rcache/rc_base.c
+++ b/src/lib/krb5/rcache/rc_base.c
@@ -44,10 +44,8 @@ krb5_error_code
 krb5_rc_register_type(krb5_context context, const krb5_rc_ops *ops)
 {
     struct krb5_rc_typelist *t;
-    krb5_error_code err;
-    err = k5_mutex_lock(&rc_typelist_lock);
-    if (err)
-        return err;
+
+    k5_mutex_lock(&rc_typelist_lock);
     for (t = typehead;t && strcmp(t->ops->type,ops->type);t = t->next)
         ;
     if (t) {
@@ -76,9 +74,7 @@ krb5_rc_resolve_type(krb5_context context, krb5_rcache *idptr, char *type)
     *idptr = NULL;
 
     /* Find the named type in the list. */
-    err = k5_mutex_lock(&rc_typelist_lock);
-    if (err)
-        return err;
+    k5_mutex_lock(&rc_typelist_lock);
     for (t = typehead; t && strcmp(t->ops->type, type); t = t->next)
         ;
     k5_mutex_unlock(&rc_typelist_lock);
diff --git a/src/lib/krb5/rcache/rc_dfl.c b/src/lib/krb5/rcache/rc_dfl.c
index 12e2a5d..70d98c1 100644
--- a/src/lib/krb5/rcache/rc_dfl.c
+++ b/src/lib/krb5/rcache/rc_dfl.c
@@ -201,12 +201,9 @@ krb5_error_code KRB5_CALLCONV
 krb5_rc_dfl_get_span(krb5_context context, krb5_rcache id,
                      krb5_deltat *lifespan)
 {
-    krb5_error_code err;
     struct dfl_data *t;
 
-    err = k5_mutex_lock(&id->lock);
-    if (err)
-        return err;
+    k5_mutex_lock(&id->lock);
     t = (struct dfl_data *) id->data;
     *lifespan = t->lifespan;
     k5_mutex_unlock(&id->lock);
@@ -239,9 +236,7 @@ krb5_rc_dfl_init(krb5_context context, krb5_rcache id, krb5_deltat lifespan)
 {
     krb5_error_code retval;
 
-    retval = k5_mutex_lock(&id->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&id->lock);
     retval = krb5_rc_dfl_init_locked(context, id, lifespan);
     k5_mutex_unlock(&id->lock);
     return retval;
@@ -276,10 +271,7 @@ krb5_rc_dfl_close_no_free(krb5_context context, krb5_rcache id)
 krb5_error_code KRB5_CALLCONV
 krb5_rc_dfl_close(krb5_context context, krb5_rcache id)
 {
-    krb5_error_code retval;
-    retval = k5_mutex_lock(&id->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&id->lock);
     krb5_rc_dfl_close_no_free(context, id);
     k5_mutex_unlock(&id->lock);
     k5_mutex_destroy(&id->lock);
@@ -624,9 +616,8 @@ krb5_error_code KRB5_CALLCONV
 krb5_rc_dfl_recover(krb5_context context, krb5_rcache id)
 {
     krb5_error_code ret;
-    ret = k5_mutex_lock(&id->lock);
-    if (ret)
-        return ret;
+
+    k5_mutex_lock(&id->lock);
     ret = krb5_rc_dfl_recover_locked(context, id);
     k5_mutex_unlock(&id->lock);
     return ret;
@@ -638,9 +629,7 @@ krb5_rc_dfl_recover_or_init(krb5_context context, krb5_rcache id,
 {
     krb5_error_code retval;
 
-    retval = k5_mutex_lock(&id->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&id->lock);
     retval = krb5_rc_dfl_recover_locked(context, id);
     if (retval)
         retval = krb5_rc_dfl_init_locked(context, id, lifespan);
@@ -727,9 +716,7 @@ krb5_rc_dfl_store(krb5_context context, krb5_rcache id, krb5_donot_replay *rep)
     if (ret)
         return ret;
 
-    ret = k5_mutex_lock(&id->lock);
-    if (ret)
-        return ret;
+    k5_mutex_lock(&id->lock);
 
     switch(rc_store(context, id, rep, now, FALSE)) {
     case CMP_MALLOC:
@@ -859,9 +846,8 @@ krb5_error_code KRB5_CALLCONV
 krb5_rc_dfl_expunge(krb5_context context, krb5_rcache id)
 {
     krb5_error_code ret;
-    ret = k5_mutex_lock(&id->lock);
-    if (ret)
-        return ret;
+
+    k5_mutex_lock(&id->lock);
     ret = krb5_rc_dfl_expunge_locked(context, id);
     k5_mutex_unlock(&id->lock);
     return ret;
diff --git a/src/plugins/kdb/db2/db2_exp.c b/src/plugins/kdb/db2/db2_exp.c
index 4ae3e31..c2bad73 100644
--- a/src/plugins/kdb/db2/db2_exp.c
+++ b/src/plugins/kdb/db2/db2_exp.c
@@ -58,12 +58,11 @@
 
 k5_mutex_t *krb5_db2_mutex;
 
-#define WRAP(NAME,TYPE,ARGLIST,ARGNAMES,ERROR_RESULT)   \
+#define WRAP(NAME,TYPE,ARGLIST,ARGNAMES)                \
     static TYPE wrap_##NAME ARGLIST                     \
     {                                                   \
         TYPE result;                                    \
-        int code = k5_mutex_lock (krb5_db2_mutex);      \
-        if (code) { return ERROR_RESULT; }              \
+        k5_mutex_lock (krb5_db2_mutex);                 \
         result = NAME ARGNAMES;                         \
         k5_mutex_unlock (krb5_db2_mutex);               \
         return result;                                  \
@@ -77,8 +76,7 @@ k5_mutex_t *krb5_db2_mutex;
 #define WRAP_VOID(NAME,ARGLIST,ARGNAMES)                \
     static void wrap_##NAME ARGLIST                     \
     {                                                   \
-        int code = k5_mutex_lock (krb5_db2_mutex);      \
-        if (code) { return; }                           \
+        k5_mutex_lock (krb5_db2_mutex);                 \
         NAME ARGNAMES;                                  \
         k5_mutex_unlock (krb5_db2_mutex);               \
     }                                                   \
@@ -86,7 +84,7 @@ k5_mutex_t *krb5_db2_mutex;
     static void wrap_##NAME ()
 
 #define WRAP_K(NAME,ARGLIST,ARGNAMES)                   \
-    WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES,code)
+    WRAP(NAME,krb5_error_code,ARGLIST,ARGNAMES)
 
 WRAP_K (krb5_db2_open,
         ( krb5_context kcontext,
diff --git a/src/plugins/kdb/db2/kdb_db2.c b/src/plugins/kdb/db2/kdb_db2.c
index 62fbef7..b0cd2a5 100644
--- a/src/plugins/kdb/db2/kdb_db2.c
+++ b/src/plugins/kdb/db2/kdb_db2.c
@@ -934,7 +934,7 @@ ctx_iterate(krb5_context context, krb5_db2_context *dbc,
     DBT key, contents;
     krb5_data contdata;
     krb5_db_entry *entry;
-    krb5_error_code retval, retval2;
+    krb5_error_code retval;
     int dbret;
 
     retval = ctx_lock(context, dbc, KRB5_LOCKMODE_SHARED);
@@ -948,21 +948,12 @@ ctx_iterate(krb5_context context, krb5_db2_context *dbc,
         retval = krb5_decode_princ_entry(context, &contdata, &entry);
         if (retval)
             break;
-        retval = k5_mutex_unlock(krb5_db2_mutex);
-        if (retval)
-            break;
+        k5_mutex_unlock(krb5_db2_mutex);
         retval = (*func)(func_arg, entry);
         krb5_dbe_free(context, entry);
-        retval2 = k5_mutex_lock(krb5_db2_mutex);
-        /* Note: If re-locking fails, the wrapper in db2_exp.c will
-           still try to unlock it again.  That would be a bug.  Fix
-           when integrating the locking better.  */
+        k5_mutex_lock(krb5_db2_mutex);
         if (retval)
             break;
-        if (retval2) {
-            retval = retval2;
-            break;
-        }
         dbret = dbc->db->seq(dbc->db, &key, &contents, R_NEXT);
     }
     switch (dbret) {
diff --git a/src/plugins/kdb/ldap/libkdb_ldap/kdb_ldap_conn.c b/src/plugins/kdb/ldap/libkdb_ldap/kdb_ldap_conn.c
index 6f53640..02fbadc 100644
--- a/src/plugins/kdb/ldap/libkdb_ldap/kdb_ldap_conn.c
+++ b/src/plugins/kdb/ldap/libkdb_ldap/kdb_ldap_conn.c
@@ -162,9 +162,7 @@ krb5_ldap_db_init(krb5_context context, krb5_ldap_context *ldap_context)
     ldap_set_option(NULL, LDAP_X_OPT_CONNECT_TIMEOUT, &local_timelimit);
 #endif
 
-    st = HNDL_LOCK(ldap_context);
-    if (st)
-        return st;
+    HNDL_LOCK(ldap_context);
     while (ldap_context->server_info_list[cnt] != NULL) {
         krb5_ldap_server_info *server_info=NULL;
 
diff --git a/src/plugins/kdb/ldap/libkdb_ldap/ldap_handle.c b/src/plugins/kdb/ldap/libkdb_ldap/ldap_handle.c
index 2261e63..2188b2d 100644
--- a/src/plugins/kdb/ldap/libkdb_ldap/ldap_handle.c
+++ b/src/plugins/kdb/ldap/libkdb_ldap/ldap_handle.c
@@ -217,9 +217,7 @@ krb5_ldap_request_handle_from_pool(krb5_ldap_context *ldap_context,
 
     *ldap_server_handle = NULL;
 
-    st = HNDL_LOCK(ldap_context);
-    if (st)
-        return st;
+    HNDL_LOCK(ldap_context);
     if (((*ldap_server_handle)=krb5_get_ldap_handle(ldap_context)) == NULL)
         (*ldap_server_handle)=krb5_retry_get_ldap_handle(ldap_context, &st);
     HNDL_UNLOCK(ldap_context);
@@ -238,9 +236,7 @@ krb5_ldap_request_next_handle_from_pool(krb5_ldap_context *ldap_context,
 {
     krb5_error_code            st=0;
 
-    st = HNDL_LOCK(ldap_context);
-    if (st)
-        return st;
+    HNDL_LOCK(ldap_context);
     (*ldap_server_handle)->server_info->server_status = OFF;
     time(&(*ldap_server_handle)->server_info->downtime);
     krb5_put_ldap_handle(*ldap_server_handle);
@@ -261,10 +257,9 @@ krb5_ldap_put_handle_to_pool(krb5_ldap_context *ldap_context,
                              krb5_ldap_server_handle *ldap_server_handle)
 {
     if (ldap_server_handle != NULL) {
-        if (HNDL_LOCK(ldap_context) == 0) {
-            krb5_put_ldap_handle(ldap_server_handle);
-            HNDL_UNLOCK(ldap_context);
-        }
+        HNDL_LOCK(ldap_context);
+        krb5_put_ldap_handle(ldap_server_handle);
+        HNDL_UNLOCK(ldap_context);
     }
     return;
 }
diff --git a/src/util/et/com_err.c b/src/util/et/com_err.c
index 96922ec..c1e3be7 100644
--- a/src/util/et/com_err.c
+++ b/src/util/et/com_err.c
@@ -106,9 +106,7 @@ void KRB5_CALLCONV com_err_va(const char *whoami,
     err = com_err_finish_init();
     if (err)
         goto best_try;
-    err = k5_mutex_lock(&com_err_hook_lock);
-    if (err)
-        goto best_try;
+    k5_mutex_lock(&com_err_hook_lock);
     p = com_err_hook ? com_err_hook : default_com_err_proc;
     (*p)(whoami, code, fmt, ap);
     k5_mutex_unlock(&com_err_hook_lock);
@@ -144,9 +142,9 @@ void KRB5_CALLCONV_C com_err(const char *whoami,
 /* Make a separate function because the assert invocations below
    use the macro expansion on some platforms, which may be insanely
    long and incomprehensible.  */
-static int com_err_lock_hook_handle(void)
+static void com_err_lock_hook_handle(void)
 {
-    return k5_mutex_lock(&com_err_hook_lock);
+    k5_mutex_lock(&com_err_hook_lock);
 }
 
 et_old_error_hook_func set_com_err_hook (et_old_error_hook_func new_proc)
@@ -156,8 +154,7 @@ et_old_error_hook_func set_com_err_hook (et_old_error_hook_func new_proc)
     /* Broken initialization?  What can we do?  */
     if (com_err_finish_init() != 0)
         abort();
-    if (com_err_lock_hook_handle() != 0)
-        abort();
+    com_err_lock_hook_handle();
     x = com_err_hook;
     com_err_hook = new_proc;
     k5_mutex_unlock(&com_err_hook_lock);
@@ -171,8 +168,7 @@ et_old_error_hook_func reset_com_err_hook ()
     /* Broken initialization?  What can we do?  */
     if (com_err_finish_init() != 0)
         abort();
-    if (com_err_lock_hook_handle() != 0)
-        abort();
+    com_err_lock_hook_handle();
     x = com_err_hook;
     com_err_hook = NULL;
     k5_mutex_unlock(&com_err_hook_lock);
diff --git a/src/util/et/error_message.c b/src/util/et/error_message.c
index 01f2c03..50ede70 100644
--- a/src/util/et/error_message.c
+++ b/src/util/et/error_message.c
@@ -75,8 +75,7 @@ void com_err_terminate(void)
 #endif
     k5_key_delete(K5_KEY_COM_ERR);
     k5_mutex_destroy(&com_err_hook_lock);
-    if (k5_mutex_lock(&et_list_lock) != 0)
-        return;
+    k5_mutex_lock(&et_list_lock);
     for (e = et_list; e; e = enext) {
         enext = e->next;
         free(e);
@@ -121,7 +120,6 @@ error_message(long code)
     unsigned int divisor = 100;
     char *cp, *cp1;
     const struct error_table *table;
-    int merr;
 
     l_offset = (unsigned long)code & ((1<<ERRCODE_RANGE)-1);
     offset = l_offset;
@@ -159,9 +157,7 @@ error_message(long code)
 
     if (CALL_INIT_FUNCTION(com_err_initialize))
         return 0;
-    merr = k5_mutex_lock(&et_list_lock);
-    if (merr)
-        goto oops;
+    k5_mutex_lock(&et_list_lock);
     dprintf(("scanning list for %x\n", table_num));
     for (e = et_list; e != NULL; e = e->next) {
         dprintf(("\t%x = %s\n", e->table->base & ERRCODE_MAX,
@@ -276,7 +272,6 @@ errcode_t KRB5_CALLCONV
 add_error_table(const struct error_table *et)
 {
     struct et_list *e;
-    int merr;
 
     if (CALL_INIT_FUNCTION(com_err_initialize))
         return 0;
@@ -287,11 +282,7 @@ add_error_table(const struct error_table *et)
 
     e->table = et;
 
-    merr = k5_mutex_lock(&et_list_lock);
-    if (merr) {
-        free(e);
-        return merr;
-    }
+    k5_mutex_lock(&et_list_lock);
     e->next = et_list;
     et_list = e;
 
@@ -300,20 +291,18 @@ add_error_table(const struct error_table *et)
     if (et->msgs[et->n_msgs] != NULL && et->msgs[et->n_msgs + 1] != NULL)
         bindtextdomain(et->msgs[et->n_msgs], et->msgs[et->n_msgs + 1]);
 
-    return k5_mutex_unlock(&et_list_lock);
+    k5_mutex_unlock(&et_list_lock);
+    return 0;
 }
 
 errcode_t KRB5_CALLCONV
 remove_error_table(const struct error_table *et)
 {
     struct et_list **ep, *e;
-    int merr;
 
     if (CALL_INIT_FUNCTION(com_err_initialize))
         return 0;
-    merr = k5_mutex_lock(&et_list_lock);
-    if (merr)
-        return merr;
+    k5_mutex_lock(&et_list_lock);
 
     /* Remove the entry that matches the error table instance. */
     for (ep = &et_list; *ep; ep = &(*ep)->next) {
@@ -321,7 +310,8 @@ remove_error_table(const struct error_table *et)
             e = *ep;
             *ep = e->next;
             free(e);
-            return k5_mutex_unlock(&et_list_lock);
+            k5_mutex_unlock(&et_list_lock);
+            return 0;
         }
     }
     k5_mutex_unlock(&et_list_lock);
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index b0bb087..76411db 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -239,13 +239,7 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
         return ENOMEM;
     }
 
-    retval = k5_mutex_lock(&g_shared_trees_mutex);
-    if (retval) {
-        free(expanded_filename);
-        free(prf);
-        scan_shared_trees_unlocked();
-        return retval;
-    }
+    k5_mutex_lock(&g_shared_trees_mutex);
     scan_shared_trees_locked();
     for (data = g_shared_trees; data; data = data->next) {
         if (!strcmp(data->filespec, expanded_filename)
@@ -255,7 +249,7 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
     }
     if (data) {
         data->refcount++;
-        (void) k5_mutex_unlock(&g_shared_trees_mutex);
+        k5_mutex_unlock(&g_shared_trees_mutex);
         retval = profile_update_file_data(data, NULL);
         free(expanded_filename);
         if (retval) {
@@ -268,7 +262,7 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
         scan_shared_trees_unlocked();
         return 0;
     }
-    (void) k5_mutex_unlock(&g_shared_trees_mutex);
+    k5_mutex_unlock(&g_shared_trees_mutex);
     data = profile_make_prf_data(expanded_filename);
     if (data == NULL) {
         free(prf);
@@ -291,18 +285,13 @@ errcode_t profile_open_file(const_profile_filespec_t filespec,
         return retval;
     }
 
-    retval = k5_mutex_lock(&g_shared_trees_mutex);
-    if (retval) {
-        profile_close_file(prf);
-        scan_shared_trees_unlocked();
-        return retval;
-    }
+    k5_mutex_lock(&g_shared_trees_mutex);
     scan_shared_trees_locked();
     data->flags |= PROFILE_FILE_SHARED;
     data->next = g_shared_trees;
     g_shared_trees = data;
     scan_shared_trees_locked();
-    (void) k5_mutex_unlock(&g_shared_trees_mutex);
+    k5_mutex_unlock(&g_shared_trees_mutex);
 
     *ret_prof = prf;
     return 0;
@@ -381,14 +370,12 @@ errcode_t profile_update_file_data_locked(prf_data_t data, char **ret_modspec)
 
 errcode_t profile_update_file_data(prf_data_t data, char **ret_modspec)
 {
-    errcode_t retval, retval2;
+    errcode_t retval;
 
-    retval = k5_mutex_lock(&data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&data->lock);
     retval = profile_update_file_data_locked(data, ret_modspec);
-    retval2 = k5_mutex_unlock(&data->lock);
-    return retval ? retval : retval2;
+    k5_mutex_unlock(&data->lock);
+    return retval;
 }
 
 static int
@@ -487,9 +474,8 @@ errout:
 errcode_t profile_flush_file_data_to_buffer (prf_data_t data, char **bufp)
 {
     errcode_t       retval;
-    retval = k5_mutex_lock(&data->lock);
-    if (retval)
-        return retval;
+
+    k5_mutex_lock(&data->lock);
     retval = profile_write_tree_to_buffer(data->root, bufp);
     k5_mutex_unlock(&data->lock);
     return retval;
@@ -502,9 +488,7 @@ errcode_t profile_flush_file_data(prf_data_t data)
     if (!data || data->magic != PROF_MAGIC_FILE_DATA)
         return PROF_MAGIC_FILE_DATA;
 
-    retval = k5_mutex_lock(&data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&data->lock);
 
     if ((data->flags & PROFILE_FILE_DIRTY) == 0) {
         k5_mutex_unlock(&data->lock);
@@ -523,9 +507,7 @@ errcode_t profile_flush_file_data_to_file(prf_data_t data, const char *outfile)
     if (!data || data->magic != PROF_MAGIC_FILE_DATA)
         return PROF_MAGIC_FILE_DATA;
 
-    retval = k5_mutex_lock(&data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&data->lock);
     retval = write_data_to_file(data, outfile, 1);
     k5_mutex_unlock(&data->lock);
     return retval;
@@ -535,12 +517,9 @@ errcode_t profile_flush_file_data_to_file(prf_data_t data, const char *outfile)
 
 void profile_dereference_data(prf_data_t data)
 {
-    int err;
-    err = k5_mutex_lock(&g_shared_trees_mutex);
-    if (err)
-        return;
+    k5_mutex_lock(&g_shared_trees_mutex);
     profile_dereference_data_locked(data);
-    (void) k5_mutex_unlock(&g_shared_trees_mutex);
+    k5_mutex_unlock(&g_shared_trees_mutex);
 }
 void profile_dereference_data_locked(prf_data_t data)
 {
@@ -551,13 +530,13 @@ void profile_dereference_data_locked(prf_data_t data)
     scan_shared_trees_locked();
 }
 
-int profile_lock_global()
+void profile_lock_global()
 {
-    return k5_mutex_lock(&g_shared_trees_mutex);
+    k5_mutex_lock(&g_shared_trees_mutex);
 }
-int profile_unlock_global()
+void profile_unlock_global()
 {
-    return k5_mutex_unlock(&g_shared_trees_mutex);
+    k5_mutex_unlock(&g_shared_trees_mutex);
 }
 
 void profile_free_file(prf_file_t prf)
diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c
index 5b2bb22..4e3d84e 100644
--- a/src/util/profile/prof_init.c
+++ b/src/util/profile/prof_init.c
@@ -278,13 +278,7 @@ copy_vtable_profile(profile_t profile, profile_t *ret_new_profile)
 
     /* Increment the refcount on the library handle if there is one. */
     if (profile->lib_handle) {
-        err = k5_mutex_lock(&profile->lib_handle->lock);
-        if (err) {
-            /* Don't decrement the refcount we failed to increment. */
-            new_profile->lib_handle = NULL;
-            profile_abandon(new_profile);
-            return err;
-        }
+        k5_mutex_lock(&profile->lib_handle->lock);
         profile->lib_handle->refcount++;
         k5_mutex_unlock(&profile->lib_handle->lock);
     }
@@ -479,7 +473,6 @@ void KRB5_CALLCONV
 profile_abandon(profile_t profile)
 {
     prf_file_t      p, next;
-    errcode_t       err;
 
     if (!profile || profile->magic != PROF_MAGIC_PROFILE)
         return;
@@ -489,13 +482,13 @@ profile_abandon(profile_t profile)
             profile->vt->cleanup(profile->cbdata);
         if (profile->lib_handle) {
             /* Decrement the refcount on the handle and maybe free it. */
-            err = k5_mutex_lock(&profile->lib_handle->lock);
-            if (!err && --profile->lib_handle->refcount == 0) {
+            k5_mutex_lock(&profile->lib_handle->lock);
+            if (--profile->lib_handle->refcount == 0) {
                 krb5int_close_plugin(profile->lib_handle->plugin_handle);
                 k5_mutex_unlock(&profile->lib_handle->lock);
                 k5_mutex_destroy(&profile->lib_handle->lock);
                 free(profile->lib_handle);
-            } else if (!err)
+            } else
                 k5_mutex_unlock(&profile->lib_handle->lock);
         }
         free(profile->vt);
diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h
index da1b937..6700b50 100644
--- a/src/util/profile/prof_int.h
+++ b/src/util/profile/prof_int.h
@@ -244,8 +244,8 @@ int profile_file_is_writable
 void profile_dereference_data (prf_data_t);
 void profile_dereference_data_locked (prf_data_t);
 
-int profile_lock_global (void);
-int profile_unlock_global (void);
+void profile_lock_global (void);
+void profile_unlock_global (void);
 
 /* prof_init.c -- included from profile.h */
 errcode_t profile_ser_size
diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c
index 52e5b05..b210236 100644
--- a/src/util/profile/prof_set.c
+++ b/src/util/profile/prof_set.c
@@ -34,9 +34,7 @@ static errcode_t rw_setup(profile_t profile)
 
     file = profile->first_file;
 
-    retval = profile_lock_global();
-    if (retval)
-        return retval;
+    profile_lock_global();
 
     /* Don't update the file if we've already made modifications */
     if (file->data->flags & PROFILE_FILE_DIRTY) {
@@ -106,9 +104,7 @@ profile_update_relation(profile_t profile, const char **names,
     if (!old_value || !*old_value)
         return PROF_EINVAL;
 
-    retval = k5_mutex_lock(&profile->first_file->data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&profile->first_file->data->lock);
     section = profile->first_file->data->root;
     for (cpp = names; cpp[1]; cpp++) {
         state = 0;
@@ -214,9 +210,7 @@ profile_rename_section(profile_t profile, const char **names,
     if (names == 0 || names[0] == 0 || names[1] == 0)
         return PROF_BAD_NAMESET;
 
-    retval = k5_mutex_lock(&profile->first_file->data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&profile->first_file->data->lock);
     section = profile->first_file->data->root;
     for (cpp = names; cpp[1]; cpp++) {
         state = 0;
@@ -273,9 +267,7 @@ profile_add_relation(profile_t profile, const char **names,
     if (names == 0 || names[0] == 0 || names[1] == 0)
         return PROF_BAD_NAMESET;
 
-    retval = k5_mutex_lock(&profile->first_file->data->lock);
-    if (retval)
-        return retval;
+    k5_mutex_lock(&profile->first_file->data->lock);
     section = profile->first_file->data->root;
     for (cpp = names; cpp[1]; cpp++) {
         state = 0;
diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c
index 4543441..cc5bdfd 100644
--- a/src/util/profile/prof_tree.c
+++ b/src/util/profile/prof_tree.c
@@ -468,11 +468,8 @@ errcode_t profile_node_iterator(void **iter_p,
      * If the file has changed, then the node pointer is invalid,
      * so we'll have search the file again looking for it.
      */
-    if (iter->file) {
-        retval = k5_mutex_lock(&iter->file->data->lock);
-        if (retval)
-            return retval;
-    }
+    if (iter->file)
+        k5_mutex_lock(&iter->file->data->lock);
     if (iter->node && (iter->file->data->upd_serial != iter->file_serial)) {
         iter->flags &= ~PROFILE_ITER_FINAL_SEEN;
         skip_num = iter->num;
@@ -503,13 +500,8 @@ get_new_file:
             if (retval == ENOENT || retval == EACCES) {
                 /* XXX memory leak? */
                 iter->file = iter->file->next;
-                if (iter->file) {
-                    retval = k5_mutex_lock(&iter->file->data->lock);
-                    if (retval) {
-                        profile_node_iterator_free(iter_p);
-                        return retval;
-                    }
-                }
+                if (iter->file)
+                    k5_mutex_lock(&iter->file->data->lock);
                 skip_num = 0;
                 retval = 0;
                 goto get_new_file;
@@ -541,13 +533,8 @@ get_new_file:
         if (!section) {
             k5_mutex_unlock(&iter->file->data->lock);
             iter->file = iter->file->next;
-            if (iter->file) {
-                retval = k5_mutex_lock(&iter->file->data->lock);
-                if (retval) {
-                    profile_node_iterator_free(iter_p);
-                    return retval;
-                }
-            }
+            if (iter->file)
+                k5_mutex_lock(&iter->file->data->lock);
             skip_num = 0;
             goto get_new_file;
         }
@@ -579,13 +566,8 @@ get_new_file:
     if (!p) {
         k5_mutex_unlock(&iter->file->data->lock);
         iter->file = iter->file->next;
-        if (iter->file) {
-            retval = k5_mutex_lock(&iter->file->data->lock);
-            if (retval) {
-                profile_node_iterator_free(iter_p);
-                return retval;
-            }
-        }
+        if (iter->file)
+            k5_mutex_lock(&iter->file->data->lock);
         iter->node = 0;
         skip_num = 0;
         goto get_new_file;
diff --git a/src/util/support/errors.c b/src/util/support/errors.c
index 1c13a4a..d820873 100644
--- a/src/util/support/errors.c
+++ b/src/util/support/errors.c
@@ -108,9 +108,10 @@ k5_get_error(struct errinfo *ep, long code)
     if (code == ep->code && ep->msg != NULL)
         return oom_check(strdup(ep->msg));
 
-    if (initialize() || lock())
+    if (initialize())
         return oom_check(strdup(_("Kerberos library initialization failure")));
 
+    lock();
     if (fptr == NULL) {
         unlock();
 #ifdef HAVE_STRERROR_R
@@ -153,8 +154,7 @@ void
 k5_set_error_info_callout_fn(const char *(KRB5_CALLCONV *f)(long))
 {
     initialize();
-    if (lock() == 0) {
-        fptr = f;
-        unlock();
-    }
+    lock();
+    fptr = f;
+    unlock();
 }
diff --git a/src/util/support/threads.c b/src/util/support/threads.c
index 4370c05..a977896 100644
--- a/src/util/support/threads.c
+++ b/src/util/support/threads.c
@@ -180,35 +180,36 @@ static void thread_termination(void *);
 
 static void thread_termination (void *tptr)
 {
-    int err = k5_mutex_lock(&key_lock);
-    if (err == 0) {
-        int i, pass, none_found;
-        struct tsd_block *t = tptr;
-
-        /* Make multiple passes in case, for example, a libkrb5 cleanup
-           function wants to print out an error message, which causes
-           com_err to allocate a thread-specific buffer, after we just
-           freed up the old one.
-
-           Shouldn't actually happen, if we're careful, but check just in
-           case.  */
-
-        pass = 0;
-        none_found = 0;
-        while (pass < 4 && !none_found) {
-            none_found = 1;
-            for (i = 0; i < K5_KEY_MAX; i++) {
-                if (destructors_set[i] && destructors[i] && t->values[i]) {
-                    void *v = t->values[i];
-                    t->values[i] = 0;
-                    (*destructors[i])(v);
-                    none_found = 0;
-                }
+    int i, pass, none_found;
+    struct tsd_block *t = tptr;
+
+    k5_mutex_lock(&key_lock);
+
+    /*
+     * Make multiple passes in case, for example, a libkrb5 cleanup
+     * function wants to print out an error message, which causes
+     * com_err to allocate a thread-specific buffer, after we just
+     * freed up the old one.
+     *
+     * Shouldn't actually happen, if we're careful, but check just in
+     * case.
+     */
+
+    pass = 0;
+    none_found = 0;
+    while (pass < 4 && !none_found) {
+        none_found = 1;
+        for (i = 0; i < K5_KEY_MAX; i++) {
+            if (destructors_set[i] && destructors[i] && t->values[i]) {
+                void *v = t->values[i];
+                t->values[i] = 0;
+                (*destructors[i])(v);
+                none_found = 0;
             }
         }
-        free (t);
-        err = k5_mutex_unlock(&key_lock);
     }
+    free (t);
+    k5_mutex_unlock(&key_lock);
 
     /* remove thread from global linked list */
 }
@@ -328,7 +329,6 @@ int k5_key_register (k5_key_t keynum, void (*destructor)(void *))
     assert(destructors_set[keynum] == 0);
     destructors[keynum] = destructor;
     destructors_set[keynum] = 1;
-    err = 0;
 
 #elif defined(_WIN32)
 
@@ -338,17 +338,14 @@ int k5_key_register (k5_key_t keynum, void (*destructor)(void *))
     destructors_set[keynum] = 1;
     destructors[keynum] = destructor;
     LeaveCriticalSection(&key_lock);
-    err = 0;
 
 #else /* POSIX */
 
-    err = k5_mutex_lock(&key_lock);
-    if (err == 0) {
-        assert(destructors_set[keynum] == 0);
-        destructors_set[keynum] = 1;
-        destructors[keynum] = destructor;
-        err = k5_mutex_unlock(&key_lock);
-    }
+    k5_mutex_lock(&key_lock);
+    assert(destructors_set[keynum] == 0);
+    destructors_set[keynum] = 1;
+    destructors[keynum] = destructor;
+    k5_mutex_unlock(&key_lock);
 
 #endif
     return 0;
@@ -381,21 +378,12 @@ int k5_key_delete (k5_key_t keynum)
 
 #else /* POSIX */
 
-    {
-        int err;
-
-        /* XXX RESOURCE LEAK:
-
-           Need to destroy the allocated objects first!  */
-
-        err = k5_mutex_lock(&key_lock);
-        if (err == 0) {
-            assert(destructors_set[keynum] == 1);
-            destructors_set[keynum] = 0;
-            destructors[keynum] = NULL;
-            k5_mutex_unlock(&key_lock);
-        }
-    }
+    /* XXX RESOURCE LEAK: Need to destroy the allocated objects first!  */
+    k5_mutex_lock(&key_lock);
+    assert(destructors_set[keynum] == 1);
+    destructors_set[keynum] = 0;
+    destructors[keynum] = NULL;
+    k5_mutex_unlock(&key_lock);
 
 #endif
 
@@ -512,13 +500,13 @@ krb5int_mutex_free (k5_mutex_t *m)
 }
 
 /* Callable versions of the various macros.  */
-int KRB5_CALLCONV
+void KRB5_CALLCONV
 krb5int_mutex_lock (k5_mutex_t *m)
 {
-    return k5_mutex_lock (m);
+    k5_mutex_lock (m);
 }
-int KRB5_CALLCONV
+void KRB5_CALLCONV
 krb5int_mutex_unlock (k5_mutex_t *m)
 {
-    return k5_mutex_unlock (m);
+    k5_mutex_unlock (m);
 }


More information about the cvs-krb5 mailing list