]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/operation.c
Fix dbcache/entry lock deadlock. If dbcache lock is held, it's
[openldap] / servers / slapd / operation.c
index a960c30695d509ec1901c2a3bcea05fa413e7df2..2fff851887656720e1705ec74cb54f7982fbf770 100644 (file)
@@ -3,28 +3,35 @@
 #include "portable.h"
 
 #include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/string.h>
+#include <ac/socket.h>
+
 #include "slap.h"
 
-extern time_t          currenttime;
-extern pthread_mutex_t currenttime_mutex;
 
 void
-op_free( Operation *op )
+slap_op_free( Operation *op )
 {
-       if ( op->o_ber != NULL )
+       ldap_pvt_thread_mutex_lock( &op->o_abandonmutex );
+
+       if ( op->o_ber != NULL ) {
                ber_free( op->o_ber, 1 );
+       }
        if ( op->o_dn != NULL ) {
                free( op->o_dn );
        }
-       /* pthread_mutex_destroy( &op->o_abandonmutex ); */
+       if ( op->o_ndn != NULL ) {
+               free( op->o_ndn );
+       }
+
+       ldap_pvt_thread_mutex_unlock( &op->o_abandonmutex );
+       ldap_pvt_thread_mutex_destroy( &op->o_abandonmutex );
        free( (char *) op );
 }
 
 Operation *
-op_add(
+slap_op_add(
     Operation          **olist,
     BerElement         *ber,
     unsigned long      msgid,
@@ -39,17 +46,20 @@ op_add(
        for ( tmp = olist; *tmp != NULL; tmp = &(*tmp)->o_next )
                ;       /* NULL */
 
-       *tmp = (Operation *) calloc( 1, sizeof(Operation) );
-       pthread_mutex_init( &(*tmp)->o_abandonmutex,
-           pthread_mutexattr_default );
+       *tmp = (Operation *) ch_calloc( 1, sizeof(Operation) );
+
+       ldap_pvt_thread_mutex_init( &(*tmp)->o_abandonmutex );
        (*tmp)->o_ber = ber;
        (*tmp)->o_msgid = msgid;
        (*tmp)->o_tag = tag;
        (*tmp)->o_abandon = 0;
-       (*tmp)->o_dn = strdup( dn != NULL ? dn : "" );
-       pthread_mutex_lock( &currenttime_mutex );
+
+       (*tmp)->o_dn = ch_strdup( dn != NULL ? dn : "" );
+       (*tmp)->o_ndn = dn_normalize_case( ch_strdup( (*tmp)->o_dn ) );
+
+       ldap_pvt_thread_mutex_lock( &currenttime_mutex );
        (*tmp)->o_time = currenttime;
-       pthread_mutex_unlock( &currenttime_mutex );
+       ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
        (*tmp)->o_opid = id;
        (*tmp)->o_connid = connid;
        (*tmp)->o_next = NULL;
@@ -58,7 +68,7 @@ op_add(
 }
 
 void
-op_delete( Operation **olist, Operation *op )
+slap_op_delete( Operation **olist, Operation *op )
 {
        Operation       **tmp;
 
@@ -66,11 +76,12 @@ op_delete( Operation **olist, Operation *op )
                ;       /* NULL */
 
        if ( *tmp == NULL ) {
-               Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %d\n",
+               Debug( LDAP_DEBUG_ANY, "op_delete: can't find op %ld\n",
                    op->o_msgid, 0, 0 );
+               slap_op_free( op );
                return; 
        }
 
        *tmp = (*tmp)->o_next;
-       op_free( op );
+       slap_op_free( op );
 }