- LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
- if ( o->o_msgid == id ) {
- LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops, o, slap_op, o_next );
- slap_op_free( o );
- goto done;
+ if ( o == NULL ) {
+ msg = "not found";
+ /* The operation is not active. Just discard it if found. */
+ LDAP_STAILQ_FOREACH( o, &op->o_conn->c_pending_ops, o_next ) {
+ if ( o->o_msgid == id ) {
+ msg = "discarded";
+ /* FIXME: This traverses c_pending_ops yet again. */
+ LDAP_STAILQ_REMOVE( &op->o_conn->c_pending_ops,
+ o, Operation, o_next );
+ LDAP_STAILQ_NEXT(o, o_next) = NULL;
+ op->o_conn->c_n_ops_pending--;
+ slap_op_free( o, NULL );
+ break;
+ }