]> git.sur5r.net Git - openldap/commitdiff
rework internal handling of strings to minimize temporary allocation; impacts rewrite...
authorPierangelo Masarati <ando@openldap.org>
Sat, 1 Jan 2005 16:10:25 +0000 (16:10 +0000)
committerPierangelo Masarati <ando@openldap.org>
Sat, 1 Jan 2005 16:10:25 +0000 (16:10 +0000)
libraries/librewrite/context.c
libraries/librewrite/info.c
libraries/librewrite/rewrite.c
libraries/librewrite/rule.c
servers/slapd/saslauthz.c

index aad9f0a0df65f00e6d62e473852047b076fb8062..cb1cb3ec7cf9926e689a470ed0f8aae69d8ca75b 100644 (file)
@@ -296,7 +296,7 @@ rewrite_context_apply(
 
                                if ( do_continue ) {
                                        if ( rule->lr_next == NULL ) {
-                                               res = ( s == string ? strdup( s ) : s );
+                                               res = s;
                                        }
                                        goto rc_continue;
                                }
@@ -321,7 +321,7 @@ rewrite_context_apply(
                        if ( res != NULL ) {
                                struct rewrite_action *action;
                                
-                               if (s != string ) {
+                               if ( s != string && s != res ) {
                                        free( s );
                                }
                                s = res;
@@ -381,7 +381,7 @@ rewrite_context_apply(
                         * result back to the string
                         */
                        } else if ( rule->lr_next == NULL ) {
-                               res = ( s == string ? strdup( s ) : s );
+                               res = s;
                        }
                        
                        break;
index c11bc399a5e0fce8ea29afff64d27351843866fc..aa07e3921b515701f0592a8a0c726d33861252a5 100644 (file)
@@ -261,7 +261,9 @@ rewrite_session(
        case REWRITE_REGEXEC_UNWILLING:
        case REWRITE_REGEXEC_ERR:
                if ( *result != NULL ) {
-                       free( *result );
+                       if ( *result != string ) {
+                               free( *result );
+                       }
                        *result = NULL;
                }
 
index 1964deba52004c567056f58ab35efb09da72163d..6eb0d71711201c4bac0cb49bbb820f4fe2de985a 100644 (file)
@@ -36,7 +36,7 @@ int ldap_debug;
 int ldap_syslog;
 int ldap_syslog_level;
 
-char *
+static void
 apply( 
                FILE *fin, 
                const char *rewriteContext,
@@ -58,11 +58,12 @@ apply(
 
        rewrite_session_init( info, cookie );
 
-       string = strdup( arg );
+       string = (char *)arg;
        for ( sep = strchr( rewriteContext, ',' );
                        rewriteContext != NULL;
                        rewriteContext = sep,
-                       sep ? sep = strchr( rewriteContext, ',' ) : NULL ) {
+                       sep ? sep = strchr( rewriteContext, ',' ) : NULL )
+       {
                char    *errmsg = "";
 
                if ( sep != NULL ) {
@@ -105,17 +106,19 @@ apply(
                if ( result == NULL ) {
                        break;
                }
-               free( string );
+               if ( string != arg && string != result ) {
+                       free( string );
+               }
                string = result;
        }
 
-       free( string );
+       if ( result && result != arg ) {
+               free( result );
+       }
 
        rewrite_session_delete( info, cookie );
 
        rewrite_info_delete( &info );
-
-       return result;
 }
 
 int
index ceeec1580c248d3f67a55dfe92a168020a3d2914..f7ea9c9d82aa61c149bf5f40b218a57447627e04 100644 (file)
@@ -419,9 +419,8 @@ recurse:;
        
        op->lo_num_passes++;
        if ( regexec( &rule->lr_regex, string, nmatch, match, 0 ) != 0 ) {
-               if ( *result == NULL && strcnt > 0 ) {
+               if ( *result == NULL && string != arg ) {
                        free( string );
-                       string = NULL;
                }
 
                /*
@@ -435,7 +434,7 @@ recurse:;
 
        *result = val.bv_val;
        val.bv_val = NULL;
-       if ( strcnt > 0 ) {
+       if ( string != arg ) {
                free( string );
                string = NULL;
        }
index a770ef62a812f0cece2c7efe4d330cf63964b5ee..df3cde64ab940c41f6f7e7bd46ef143b9ef3ffa2 100644 (file)
@@ -700,7 +700,9 @@ static int slap_authz_regexp( struct berval *in, struct berval *out,
                if ( !BER_BVISNULL( out ) ) {
                        char *val = out->bv_val;
                        ber_str2bv_x( val, 0, 1, out, ctx );
-                       free( val );
+                       if ( val != in->bv_val ) {
+                               free( val );
+                       }
                } else {
                        ber_dupbv_x( out, in, ctx );
                }