]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/operation.c
ITS#6944 limit op cache to 10 ops per thread
[openldap] / servers / slapd / operation.c
index b3ec0372bc4d389353227b4b128ddd22d5e66c01..ae7b4a8a7271e78c910873a33431ba71eb32a73b 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 1998-2008 The OpenLDAP Foundation.
+ * Copyright 1998-2011 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -111,16 +111,37 @@ slap_op_free( Operation *op, void *ctx )
        }
 #endif /* defined( LDAP_SLAPI ) */
 
+       if ( !BER_BVISNULL( &op->o_csn ) ) {
+               op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
+               BER_BVZERO( &op->o_csn );
+       }
+
+       if ( op->o_pagedresults_state != NULL ) {
+               op->o_tmpfree( op->o_pagedresults_state, op->o_tmpmemctx );
+               op->o_pagedresults_state = NULL;
+       }
+
        opbuf = (OperationBuffer *) op;
        memset( opbuf, 0, sizeof(*opbuf) );
        op->o_hdr = &opbuf->ob_hdr;
        op->o_controls = opbuf->ob_controls;
 
        if ( ctx ) {
-               void *op2 = NULL;
+               Operation *op2 = NULL;
                ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
                        op, slap_op_q_destroy, &op2, NULL );
                LDAP_STAILQ_NEXT( op, o_next ) = op2;
+               if ( op2 ) {
+                       op->o_tincr = op2->o_tincr + 1;
+                       /* No more than 10 ops on per-thread free list */
+                       if ( op->o_tincr > 10 ) {
+                               ldap_pvt_thread_pool_setkey( ctx, (void *)slap_op_free,
+                                       op2, slap_op_q_destroy, NULL, NULL );
+                               ber_memfree_x( op, NULL );
+                       }
+               } else {
+                       op->o_tincr = 1;
+               }
        } else {
                ber_memfree_x( op, NULL );
        }