]> git.sur5r.net Git - openldap/commitdiff
prettify matchedDN; fix memory handling
authorPierangelo Masarati <ando@openldap.org>
Sat, 27 Aug 2005 19:21:43 +0000 (19:21 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 27 Aug 2005 19:21:43 +0000 (19:21 +0000)
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/search.c

index 3ce113c13092dd43d6ad152fde305530b5315b6f..0cb7f3337ea55c9f91f3b7fd243a4b2f5e4e34e6 100644 (file)
@@ -667,8 +667,6 @@ meta_back_op_result(
                                rerr = LDAP_SUCCESS;
        char                    *rmsg = NULL;
        char                    *rmatch = NULL;
-       int                     free_rmsg = 0,
-                               free_rmatch = 0;
 
        if ( candidate != META_TARGET_NONE ) {
                metasingleconn_t        *msc = &mc->mc_conns[ candidate ];
@@ -685,17 +683,20 @@ meta_back_op_result(
                         */
                        ldap_get_option( msc->msc_ld,
                                        LDAP_OPT_ERROR_STRING, &rmsg );
+                       if ( rmsg != NULL && rmsg[ 0 ] == '\0' ) {
+                               ldap_memfree( rmsg );
+                               rmsg = NULL;
+                       }
+
                        ldap_get_option( msc->msc_ld,
                                        LDAP_OPT_MATCHED_DN, &rmatch );
-                       rerr = rs->sr_err = slap_map_api2result( rs );
-
-                       if ( rmsg ) {
-                               free_rmsg = 1;
-                       }
-                       if ( rmatch ) {
-                               free_rmatch = 1;
+                       if ( rmatch != NULL && rmatch[ 0 ] == '\0' ) {
+                               ldap_memfree( rmatch );
+                               rmatch = NULL;
                        }
 
+                       rerr = rs->sr_err = slap_map_api2result( rs );
+
                        Debug(LDAP_DEBUG_ANY,
                                        "==> meta_back_op_result: target"
                                        " <%d> sending msg \"%s\""
@@ -722,8 +723,18 @@ meta_back_op_result(
                                 */
                                ldap_get_option( msc->msc_ld,
                                                LDAP_OPT_ERROR_STRING, &msg );
+                               if ( msg != NULL && msg[ 0 ] == '\0' ) {
+                                       ldap_memfree( msg );
+                                       msg = NULL;
+                               }
+
                                ldap_get_option( msc->msc_ld,
                                                LDAP_OPT_MATCHED_DN, &match );
+                               if ( match != NULL && match[ 0 ] == '\0' ) {
+                                       ldap_memfree( match );
+                                       match = NULL;
+                               }
+
                                rs->sr_err = slap_map_api2result( rs );
        
                                Debug(LDAP_DEBUG_ANY,
@@ -739,27 +750,29 @@ meta_back_op_result(
                                switch ( rs->sr_err ) {
                                default:
                                        rerr = rs->sr_err;
-                                       if ( rmsg ) {
-                                               ber_memfree( rmsg );
+                                       if ( msg != NULL ) {
+                                               if ( rmsg ) {
+                                                       ldap_memfree( rmsg );
+                                               }
+                                               rmsg = msg;
+                                               msg = NULL;
                                        }
-                                       rmsg = msg;
-                                       free_rmsg = 1;
-                                       msg = NULL;
-                                       if ( rmatch ) {
-                                               ber_memfree( rmatch );
+                                       if ( match != NULL ) {
+                                               if ( rmatch ) {
+                                                       ldap_memfree( rmatch );
+                                               }
+                                               rmatch = match;
+                                               match = NULL;
                                        }
-                                       rmatch = match;
-                                       free_rmatch = 1;
-                                       match = NULL;
                                        break;
                                }
+
+                               if ( msg ) {
+                                       ldap_memfree( msg );
+                               }
        
-                               /* better test the pointers before freeing? */
                                if ( match ) {
-                                       free( match );
-                               }
-                               if ( msg ) {
-                                       free( msg );
+                                       ldap_memfree( match );
                                }
                        }
                }
@@ -767,16 +780,35 @@ meta_back_op_result(
        
        rs->sr_err = rerr;
        rs->sr_text = rmsg;
-       rs->sr_matched = rmatch;
+       if ( rmatch != NULL ) {
+               struct berval   dn, pdn;
+
+               ber_str2bv( rmatch, 0, 0, &dn );
+               if ( dnPretty( NULL, &dn, &pdn, op->o_tmpmemctx ) == LDAP_SUCCESS ) {
+                       rs->sr_matched = pdn.bv_val;
+                       ldap_memfree( rmatch );
+                       rmatch = NULL;
+               } else {
+                       rs->sr_matched = rmatch;
+               }
+
+       } else {
+               rs->sr_matched = NULL;
+       }
        send_ldap_result( op, rs );
-       if ( free_rmsg ) {
+       if ( rmsg != NULL ) {
                ber_memfree( rmsg );
        }
-       if ( free_rmatch ) {
-               ber_memfree( rmatch );
+       if ( rs->sr_matched != NULL ) {
+               if ( rmatch == NULL ) {
+                       ber_memfree_x( rs->sr_matched, op->o_tmpmemctx );
+
+               } else {
+                       ldap_memfree( rmatch );
+               }
+               rs->sr_matched = NULL;
        }
        rs->sr_text = NULL;
-       rs->sr_matched = NULL;
 
        return ( ( rerr == LDAP_SUCCESS ) ? 0 : -1 );
 }
index 92e89d8c3864db1eced6914680e1b5a4dbe8ec2c..edf3975be43a8f24c5014cbae6d1334b97cb812f 100644 (file)
@@ -759,7 +759,7 @@ really_bad:;
                }
 
        } else if ( sres == LDAP_NO_SUCH_OBJECT ) {
-               matched = ch_strdup( op->o_bd->be_suffix[ 0 ].bv_val );
+               matched = op->o_bd->be_suffix[ 0 ].bv_val;
        }
 
 #if 0
@@ -804,7 +804,7 @@ really_bad:;
        rs->sr_ref = NULL;
 
 finish:;
-       if ( matched ) {
+       if ( matched && matched != op->o_bd->be_suffix[ 0 ].bv_val ) {
                op->o_tmpfree( matched, op->o_tmpmemctx );
        }