+static slap_callback rwm_cb;
+
+static void
+rwm_keyfree(
+ void *key,
+ void *data )
+{
+ ber_memfree_x( data, NULL );
+}
+
+static slap_callback *
+rwm_callback_get( Operation *op )
+{
+ void *data = NULL;
+
+ if ( op->o_threadctx == NULL ) {
+ return &rwm_cb;
+ }
+
+ ldap_pvt_thread_pool_getkey( op->o_threadctx,
+ rwm_keyfree, &data, NULL );
+ if ( data == NULL ) {
+ data = ch_calloc( sizeof( slap_callback ), 1 );
+ ldap_pvt_thread_pool_setkey( op->o_threadctx,
+ rwm_keyfree, data, rwm_keyfree );
+ }
+
+ return (slap_callback *)data;
+}
+