diff --git a/libraries/libldap/cyrus.c b/libraries/libldap/cyrus.c
index 6af6d8940cf260683b364daaa9644aa2800f4e74..fcca106b7d3b6dbf11d9f9f8e12a27d4a80fa8b9 100644
--- a/libraries/libldap/cyrus.c
+++ b/libraries/libldap/cyrus.c
@@ -16,11 +16,13 @@
 #include <ac/ctype.h>
 
 #include "ldap-int.h"
+
+#ifdef HAVE_CYRUS_SASL
+
 #ifdef LDAP_R_COMPILE
-#include "ldap_pvt_thread.h"
+ldap_pvt_thread_mutex_t ldap_int_sasl_mutex;
 #endif
 
-#ifdef HAVE_CYRUS_SASL
 #include <sasl.h>
 
 /*
@@ -62,6 +64,8 @@ int ldap_int_sasl_init( void )
 		ldap_pvt_sasl_mutex_lock,
 		ldap_pvt_sasl_mutex_unlock,    
 		ldap_pvt_sasl_mutex_dispose );    
+
+	ldap_pvt_thread_mutex_init( &ldap_int_sasl_mutex );
 #endif
 
 	if ( sasl_client_init( client_callbacks ) == SASL_OK ) {
diff --git a/libraries/libldap/sasl.c b/libraries/libldap/sasl.c
index e22b11ce96fa47f9859a9e20705a0b37471f5a5e..12cb3816638676ba485978f53ffef7c5731fa1a6 100644
--- a/libraries/libldap/sasl.c
+++ b/libraries/libldap/sasl.c
@@ -37,7 +37,6 @@
 
 #include "ldap-int.h"
 
-
 /*
  * ldap_sasl_bind - bind to the ldap server (and X.500).
  * The dn (usually NULL), mechanism, and credentials are provided.
@@ -417,13 +416,17 @@ ldap_sasl_interactive_bind_s(
 {
 	int rc;
 
+#if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL )
+	ldap_pvt_thread_mutex_lock( &ldap_int_sasl_mutex );
+#endif
+
 	if( mechs == NULL || *mechs == '\0' ) {
 		char *smechs;
 
 		rc = ldap_pvt_sasl_getmechs( ld, &smechs );
 
 		if( rc != LDAP_SUCCESS ) {
-			return rc;
+			goto done;
 		}
 
 		Debug( LDAP_DEBUG_TRACE,
@@ -442,5 +445,10 @@ ldap_sasl_interactive_bind_s(
 		serverControls, clientControls,
 		flags, interact, defaults );
 
+done:
+#if defined( LDAP_R_COMPILE ) && defined( HAVE_CYRUS_SASL )
+	ldap_pvt_thread_mutex_unlock( &ldap_int_sasl_mutex );
+#endif
+
 	return rc;
 }