]> git.sur5r.net Git - openldap/commitdiff
improve previous commit
authorPierangelo Masarati <ando@openldap.org>
Sat, 7 Jan 2006 12:35:02 +0000 (12:35 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 7 Jan 2006 12:35:02 +0000 (12:35 +0000)
servers/slapd/back-ldbm/compare.c

index 4055f4bccb8fbf6df689404439f2eed7f27683dd..7b80428047870103e5f2289b5fdba3b23a54b660 100644 (file)
@@ -36,13 +36,20 @@ ldbm_back_compare(
        Attribute       *a;
        int             manageDSAit = get_manageDSAit( op );
 
+       rs->sr_matched = NULL;
+       rs->sr_ref = NULL;
+
        /* grab giant lock for reading */
        ldap_pvt_thread_rdwr_rlock(&li->li_giant_rwlock);
 
        /* get entry with reader lock */
-       if ( (e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched )) == NULL ) {
+       e = dn2entry_r( op->o_bd, &op->o_req_ndn, &matched );
+       if ( e == NULL ) {
                if ( matched != NULL ) {
-                       rs->sr_matched = ch_strdup( matched->e_dn );
+                       struct berval   bv;
+
+                       ber_str2bv_x( matched, 0, 1, &bv, op->o_tmpmemctx );
+                       rs->sr_matched = bv.bv_val;
                        rs->sr_ref = is_entry_referral( matched )
                                ? get_entry_referrals( op, matched )
                                : NULL;
@@ -55,16 +62,12 @@ ldbm_back_compare(
                ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
 
                rs->sr_err = LDAP_REFERRAL;
-               send_ldap_result( op, rs );
-
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               free( (char *)rs->sr_matched );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
-               return rs->sr_err;
+               goto return_results;
        }
 
-       if (!manageDSAit && is_entry_referral( e ) ) {
+       if ( !manageDSAit && is_entry_referral( e ) ) {
+               struct berval   bv;
+
                /* entry is a referral, don't allow add */
                rs->sr_ref = get_entry_referrals( op, e );
 
@@ -73,12 +76,9 @@ ldbm_back_compare(
 
 
                rs->sr_err = LDAP_REFERRAL;
-               rs->sr_matched = e->e_name.bv_val;
-               send_ldap_result( op, rs );
+               ber_dupbv_x( &bv, &e->e_name, op->o_tmpmemctx );
+               rs->sr_matched = bv.bv_val;
 
-               if ( rs->sr_ref ) ber_bvarray_free( rs->sr_ref );
-               rs->sr_ref = NULL;
-               rs->sr_matched = NULL;
                goto return_results;
        }
 
@@ -113,16 +113,24 @@ return_results:;
        cache_return_entry_r( &li->li_cache, e );
        ldap_pvt_thread_rdwr_runlock(&li->li_giant_rwlock);
 
+       send_ldap_result( op, rs );
+
        switch ( rs->sr_err ) {
-       case LDAP_NO_SUCH_ATTRIBUTE:
        case LDAP_COMPARE_FALSE:
        case LDAP_COMPARE_TRUE:
-               send_ldap_result( op, rs );
-               if ( rs->sr_err != LDAP_NO_SUCH_ATTRIBUTE ) {
-                       rs->sr_err = LDAP_SUCCESS;
-               }
+               rs->sr_err = LDAP_SUCCESS;
                break;
        }
 
+       if ( rs->sr_ref != NULL ) {
+               ber_bvarray_free( rs->sr_ref );
+               rs->sr_ref = NULL;
+       }
+
+       if ( rs->sr_matched != NULL ) {
+               op->o_tmpfree( (char *)rs->sr_matched, op->o_tmpmemctx );
+               rs->sr_matched = NULL;
+       }
+
        return rs->sr_err;
 }