From: Pierangelo Masarati Date: Sat, 1 Jan 2005 16:10:25 +0000 (+0000) Subject: rework internal handling of strings to minimize temporary allocation; impacts rewrite... X-Git-Tag: OPENLDAP_REL_ENG_2_3_BP~482 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=52b878dcc098275672eece1ab8c07eca9fc28a1f;p=openldap rework internal handling of strings to minimize temporary allocation; impacts rewrite() and rewrite_session() behavior in case of no rewriting --- diff --git a/libraries/librewrite/context.c b/libraries/librewrite/context.c index aad9f0a0df..cb1cb3ec7c 100644 --- a/libraries/librewrite/context.c +++ b/libraries/librewrite/context.c @@ -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; diff --git a/libraries/librewrite/info.c b/libraries/librewrite/info.c index c11bc399a5..aa07e3921b 100644 --- a/libraries/librewrite/info.c +++ b/libraries/librewrite/info.c @@ -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; } diff --git a/libraries/librewrite/rewrite.c b/libraries/librewrite/rewrite.c index 1964deba52..6eb0d71711 100644 --- a/libraries/librewrite/rewrite.c +++ b/libraries/librewrite/rewrite.c @@ -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 diff --git a/libraries/librewrite/rule.c b/libraries/librewrite/rule.c index ceeec1580c..f7ea9c9d82 100644 --- a/libraries/librewrite/rule.c +++ b/libraries/librewrite/rule.c @@ -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; } diff --git a/servers/slapd/saslauthz.c b/servers/slapd/saslauthz.c index a770ef62a8..df3cde64ab 100644 --- a/servers/slapd/saslauthz.c +++ b/servers/slapd/saslauthz.c @@ -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 ); }