]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/cyrus.c
ITS#8262 add ldap_build_*_req functions
[openldap] / libraries / libldap / cyrus.c
index a57292800be5a9bbbaff01b57083a7504cb89a74..f073c7735f9fdcb9ae57c578ba3f62161a70cebf 100644 (file)
@@ -1,7 +1,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2013 The OpenLDAP Foundation.
+ * Copyright 1998-2015 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -493,11 +493,12 @@ ldap_int_sasl_bind(
                                if ( ldap_pvt_tls_get_unique( ssl, &cbv, 0 )) {
                                        sasl_channel_binding_t *cb = ldap_memalloc( sizeof(*cb) +
                                                cbv.bv_len);
+                                       void *cb_data; /* used since cb->data is const* */
                                        cb->name = "ldap";
                                        cb->critical = 0;
-                                       cb->data = (char *)(cb+1);
                                        cb->len = cbv.bv_len;
-                                       memcpy( cb->data, cbv.bv_val, cbv.bv_len );
+                                       cb->data = cb_data = cb+1;
+                                       memcpy( cb_data, cbv.bv_val, cbv.bv_len );
                                        sasl_setprop( ld->ld_defconn->lconn_sasl_authctx,
                                                SASL_CHANNEL_BINDING, cb );
                                        ld->ld_defconn->lconn_sasl_cbind = cb;
@@ -567,8 +568,11 @@ ldap_int_sasl_bind(
                ctx = ld->ld_defconn->lconn_sasl_authctx;
 
                rc = ldap_parse_sasl_bind_result( ld, result, &scred, 0 );
-               if ( rc != LDAP_SUCCESS )
+               if ( rc != LDAP_SUCCESS ) {
+                       if ( scred )
+                               ber_bvfree( scred );
                        goto done;
+               }
 
                rc = ldap_result2error( ld, result, 0 );
                if ( rc != LDAP_SUCCESS && rc != LDAP_SASL_BIND_IN_PROGRESS ) {
@@ -584,8 +588,11 @@ ldap_int_sasl_bind(
                }
 
                mech = *rmech;
-               if ( rc == LDAP_SUCCESS && mech == NULL )
+               if ( rc == LDAP_SUCCESS && mech == NULL ) {
+                       if ( scred )
+                               ber_bvfree( scred );
                        goto success;
+               }
 
                do {
                        if( ! scred ) {
@@ -1165,6 +1172,7 @@ void *ldap_pvt_sasl_mutex_new(void)
        if ( ldap_pvt_thread_mutex_init( mutex ) == 0 ) {
                return mutex;
        }
+       LDAP_FREE( mutex );
 #ifndef LDAP_DEBUG_R_SASL
        assert( 0 );
 #endif /* !LDAP_DEBUG_R_SASL */