mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-02 04:59:39 -05:00
more memleaks fixed; some cleanup
This commit is contained in:
parent
f23c5d9565
commit
f4e0075154
9 changed files with 90 additions and 20 deletions
|
|
@ -75,6 +75,7 @@ rewrite_parse(
|
|||
"[%s:%d] rewriteEngine needs 'state'\n%s",
|
||||
fname, lineno, "" );
|
||||
return -1;
|
||||
|
||||
} else if ( argc > 2 ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"[%s:%d] extra fields in rewriteEngine"
|
||||
|
|
@ -84,8 +85,10 @@ rewrite_parse(
|
|||
|
||||
if ( strcasecmp( argv[ 1 ], "on" ) == 0 ) {
|
||||
info->li_state = REWRITE_ON;
|
||||
|
||||
} else if ( strcasecmp( argv[ 1 ], "off" ) == 0 ) {
|
||||
info->li_state = REWRITE_OFF;
|
||||
|
||||
} else {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"[%s:%d] unknown 'state' in rewriteEngine;"
|
||||
|
|
@ -151,6 +154,7 @@ rewrite_parse(
|
|||
" 'alias'\n%s",
|
||||
fname, lineno, "" );
|
||||
return -1;
|
||||
|
||||
} else if ( argc > 4 ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"[%s:%d] extra fields in"
|
||||
|
|
@ -175,6 +179,7 @@ rewrite_parse(
|
|||
|
||||
rewrite_int_curr_context->lc_alias = aliased;
|
||||
rewrite_int_curr_context = aliased;
|
||||
|
||||
} else {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"[%s:%d] extra fields"
|
||||
|
|
@ -195,6 +200,7 @@ rewrite_parse(
|
|||
" 'subst' ['flags']\n%s",
|
||||
fname, lineno, "" );
|
||||
return -1;
|
||||
|
||||
} else if ( argc > 4 ) {
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"[%s:%d] extra fields in rewriteRule"
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ rewrite_context_apply(
|
|||
|
||||
case REWRITE_REGEXEC_ERR:
|
||||
Debug( LDAP_DEBUG_ANY, "==> rewrite_context_apply"
|
||||
" error ...\n%s%s%s", "", "", "");
|
||||
" error ...\n", 0, 0, 0);
|
||||
|
||||
/*
|
||||
* Checks for special actions to be taken
|
||||
|
|
@ -273,8 +273,7 @@ rewrite_context_apply(
|
|||
case REWRITE_ACTION_IGNORE_ERR:
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"==> rewrite_context_apply"
|
||||
" ignoring error ...\n%s%s%s",
|
||||
"", "", "" );
|
||||
" ignoring error ...\n", 0, 0, 0 );
|
||||
do_continue = 1;
|
||||
break;
|
||||
|
||||
|
|
|
|||
|
|
@ -210,13 +210,16 @@ rewrite_session(
|
|||
case REWRITE_MODE_ERR:
|
||||
rc = REWRITE_REGEXEC_ERR;
|
||||
goto rc_return;
|
||||
|
||||
case REWRITE_MODE_OK:
|
||||
rc = REWRITE_REGEXEC_OK;
|
||||
goto rc_return;
|
||||
|
||||
case REWRITE_MODE_COPY_INPUT:
|
||||
*result = strdup( string );
|
||||
rc = REWRITE_REGEXEC_OK;
|
||||
goto rc_return;
|
||||
|
||||
case REWRITE_MODE_USE_DEFAULT:
|
||||
context = rewrite_context_find( info,
|
||||
REWRITE_DEFAULT_CONTEXT );
|
||||
|
|
|
|||
|
|
@ -455,6 +455,7 @@ rewrite_builtin_map_free(
|
|||
break;
|
||||
}
|
||||
|
||||
free( map->lb_name );
|
||||
free( map );
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ rewrite_param_set(
|
|||
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
|
||||
return REWRITE_ERR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_REWRITE_LDAP_PVT_THREADS
|
||||
ldap_pvt_thread_rdwr_wunlock( &info->li_params_mutex );
|
||||
|
|
@ -117,9 +117,15 @@ rewrite_param_free(
|
|||
void *tmp
|
||||
)
|
||||
{
|
||||
char *value = ( char * )tmp;
|
||||
struct rewrite_var *var = ( struct rewrite_var * )tmp;
|
||||
assert( var != NULL );
|
||||
|
||||
free( value );
|
||||
assert( var->lv_name != NULL );
|
||||
assert( var->lv_value.bv_val != NULL );
|
||||
|
||||
free( var->lv_name );
|
||||
free( var->lv_value.bv_val );
|
||||
free( var );
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -132,7 +132,7 @@ main( int argc, char *argv[] )
|
|||
exit( EXIT_SUCCESS );
|
||||
|
||||
case 'r':
|
||||
rewriteContext = strdup( optarg );
|
||||
rewriteContext = optarg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,6 +70,39 @@ append_action(
|
|||
return REWRITE_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
destroy_action(
|
||||
struct rewrite_action **paction
|
||||
)
|
||||
{
|
||||
struct rewrite_action *action;
|
||||
|
||||
assert( paction );
|
||||
assert( *paction );
|
||||
|
||||
action = *paction;
|
||||
|
||||
/* do something */
|
||||
switch ( action->la_type ) {
|
||||
case REWRITE_FLAG_GOTO: {
|
||||
int *pi = (int *)action->la_args;
|
||||
|
||||
if ( pi ) {
|
||||
free( pi );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free( action );
|
||||
*paction = NULL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* In case of error it returns NULL and does not free all the memory
|
||||
* it allocated; as this is a once only phase, and an error at this stage
|
||||
|
|
@ -402,6 +435,7 @@ rewrite_rule_destroy(
|
|||
)
|
||||
{
|
||||
struct rewrite_rule *rule;
|
||||
struct rewrite_action *action;
|
||||
|
||||
assert( prule );
|
||||
assert( *prule );
|
||||
|
|
@ -429,6 +463,13 @@ rewrite_rule_destroy(
|
|||
|
||||
regfree( &rule->lr_regex );
|
||||
|
||||
for ( action = rule->lr_action; action; ) {
|
||||
struct rewrite_action *curraction = action;
|
||||
|
||||
action = action->la_next;
|
||||
destroy_action( &curraction );
|
||||
}
|
||||
|
||||
free( rule );
|
||||
*prule = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ rewrite_subst_compile(
|
|||
* Take care of substitution string
|
||||
*/
|
||||
for ( p = begin = result, subs_len = 0; p[ 0 ] != '\0'; p++ ) {
|
||||
|
||||
|
||||
/*
|
||||
* Keep only single escapes '%'
|
||||
*/
|
||||
|
|
@ -65,7 +65,7 @@ rewrite_subst_compile(
|
|||
continue;
|
||||
}
|
||||
|
||||
tmps = (struct berval *)realloc( subs,
|
||||
tmps = ( struct berval * )realloc( subs,
|
||||
sizeof( struct berval )*( nsub + 1 ) );
|
||||
if ( tmps == NULL ) {
|
||||
/* FIXME: cleanup */
|
||||
|
|
@ -96,14 +96,15 @@ rewrite_subst_compile(
|
|||
* Substitution pattern
|
||||
*/
|
||||
if ( isdigit( (unsigned char) p[ 1 ] ) ) {
|
||||
int d = p[ 1 ] - '0';
|
||||
struct rewrite_submatch *tmpsm;
|
||||
int d = p[ 1 ] - '0';
|
||||
|
||||
/*
|
||||
* Add a new value substitution scheme
|
||||
*/
|
||||
tmpsm = realloc( submatch,
|
||||
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
|
||||
|
||||
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
|
||||
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
|
||||
if ( tmpsm == NULL ) {
|
||||
/* cleanup */
|
||||
return NULL;
|
||||
|
|
@ -118,7 +119,9 @@ rewrite_subst_compile(
|
|||
if ( p[ 2 ] != '{' ) {
|
||||
submatch[ nsub ].ls_type =
|
||||
REWRITE_SUBMATCH_ASIS;
|
||||
submatch[ nsub ].ls_map = NULL;
|
||||
begin = ++p + 1;
|
||||
|
||||
} else {
|
||||
struct rewrite_map *map;
|
||||
|
||||
|
|
@ -131,9 +134,8 @@ rewrite_subst_compile(
|
|||
/* cleanup */
|
||||
return NULL;
|
||||
}
|
||||
p = begin - 1;
|
||||
|
||||
submatch[ nsub ].ls_map = map;
|
||||
p = begin - 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -153,7 +155,7 @@ rewrite_subst_compile(
|
|||
/*
|
||||
* Add a new value substitution scheme
|
||||
*/
|
||||
tmpsm = realloc( submatch,
|
||||
tmpsm = ( struct rewrite_submatch * )realloc( submatch,
|
||||
sizeof( struct rewrite_submatch )*( nsub + 1 ) );
|
||||
if ( tmpsm == NULL ) {
|
||||
/* cleanup */
|
||||
|
|
@ -162,7 +164,6 @@ rewrite_subst_compile(
|
|||
submatch = tmpsm;
|
||||
submatch[ nsub ].ls_type =
|
||||
REWRITE_SUBMATCH_MAP_W_ARG;
|
||||
|
||||
submatch[ nsub ].ls_map = map;
|
||||
}
|
||||
|
||||
|
|
@ -172,12 +173,12 @@ rewrite_subst_compile(
|
|||
/*
|
||||
* Last part of string
|
||||
*/
|
||||
tmps = realloc( subs, sizeof( struct berval )*( nsub + 1 ) );
|
||||
tmps = (struct berval * )realloc( subs, sizeof( struct berval )*( nsub + 1 ) );
|
||||
if ( tmps == NULL ) {
|
||||
/*
|
||||
* XXX need to free the value subst stuff!
|
||||
*/
|
||||
free( submatch );
|
||||
free( subs );
|
||||
return NULL;
|
||||
}
|
||||
subs = tmps;
|
||||
|
|
@ -235,7 +236,7 @@ submatch_copy(
|
|||
l = match[ c ].rm_eo - match[ c ].rm_so;
|
||||
|
||||
val->bv_len = l;
|
||||
val->bv_val = calloc( sizeof( char ), l + 1 );
|
||||
val->bv_val = malloc( l + 1 );
|
||||
if ( val->bv_val == NULL ) {
|
||||
return REWRITE_ERR;
|
||||
}
|
||||
|
|
@ -354,12 +355,16 @@ rewrite_subst_apply(
|
|||
rc = rewrite_xmap_apply( info, op,
|
||||
subst->lt_submatch[ n ].ls_map,
|
||||
&key, &submatch[ n ] );
|
||||
free( key.bv_val );
|
||||
key.bv_val = NULL;
|
||||
break;
|
||||
|
||||
case REWRITE_SUBMATCH_MAP_W_ARG:
|
||||
rc = rewrite_map_apply( info, op,
|
||||
subst->lt_submatch[ n ].ls_map,
|
||||
&key, &submatch[ n ] );
|
||||
free( key.bv_val );
|
||||
key.bv_val = NULL;
|
||||
break;
|
||||
|
||||
default:
|
||||
|
|
@ -388,7 +393,7 @@ rewrite_subst_apply(
|
|||
* of the subst pattern and initialize it
|
||||
*/
|
||||
l += subst->lt_subs_len;
|
||||
res = calloc( sizeof( char ), l + 1 );
|
||||
res = malloc( l + 1 );
|
||||
if ( res == NULL ) {
|
||||
rc = REWRITE_REGEXEC_ERR;
|
||||
goto cleanup;
|
||||
|
|
@ -410,7 +415,9 @@ rewrite_subst_apply(
|
|||
if ( subst->lt_subs[ n ].bv_val != NULL ) {
|
||||
AC_MEMCPY( res + cl, subst->lt_subs[ n ].bv_val,
|
||||
subst->lt_subs[ n ].bv_len );
|
||||
cl += subst->lt_subs[ n ].bv_len;
|
||||
}
|
||||
res[ cl ] = '\0';
|
||||
|
||||
val->bv_val = res;
|
||||
val->bv_len = l;
|
||||
|
|
@ -467,12 +474,18 @@ rewrite_subst_destroy(
|
|||
}
|
||||
}
|
||||
|
||||
free( subst->lt_submatch );
|
||||
subst->lt_submatch = NULL;
|
||||
|
||||
/* last one */
|
||||
if ( subst->lt_subs[ n ].bv_val ) {
|
||||
free( subst->lt_subs[ n ].bv_val );
|
||||
subst->lt_subs[ n ].bv_val = NULL;
|
||||
}
|
||||
|
||||
free( subst->lt_subs );
|
||||
subst->lt_subs = NULL;
|
||||
|
||||
free( subst );
|
||||
*psubst = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -494,6 +494,7 @@ rewrite_xmap_destroy(
|
|||
|
||||
}
|
||||
|
||||
free( map->lm_name );
|
||||
free( map );
|
||||
*pmap = NULL;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue