mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-12-24 00:29:35 -05:00
rework internal handling of strings to minimize temporary allocation; impacts rewrite() and rewrite_session() behavior in case of no rewriting
This commit is contained in:
parent
1344e83342
commit
52b878dcc0
5 changed files with 21 additions and 15 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue