plug leaks

This commit is contained in:
Howard Chu 2006-03-31 20:06:49 +00:00
parent d3d7976747
commit 7fb8fd446a
3 changed files with 35 additions and 40 deletions

View File

@ -431,6 +431,7 @@ rewrite_parse_builtin_map(
* Error * Error
*/ */
} else { } else {
free( map );
Debug( LDAP_DEBUG_ANY, "[%s:%d] unknown map type\n%s", Debug( LDAP_DEBUG_ANY, "[%s:%d] unknown map type\n%s",
fname, lineno, "" ); fname, lineno, "" );
return -1; return -1;

View File

@ -99,11 +99,20 @@ destroy_action(
return 0; return 0;
} }
static int
destroy_actions(
struct rewrite_action *paction
)
{
struct rewrite_action *next;
for (; paction; paction = next) {
next = paction->la_next;
destroy_action( &paction );
}
}
/* /*
* 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
* would require the server to stop, there is no need to be paranoid
* about memory allocation
*/ */
int int
rewrite_rule_compile( rewrite_rule_compile(
@ -186,8 +195,7 @@ rewrite_rule_compile(
*/ */
action = calloc( sizeof( struct rewrite_action ), 1 ); action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) { if ( action == NULL ) {
/* cleanup ... */ goto fail;
return REWRITE_ERR;
} }
action->la_type = REWRITE_ACTION_STOP; action->la_type = REWRITE_ACTION_STOP;
@ -199,8 +207,7 @@ rewrite_rule_compile(
*/ */
action = calloc( sizeof( struct rewrite_action ), 1 ); action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) { if ( action == NULL ) {
/* cleanup ... */ goto fail;
return REWRITE_ERR;
} }
mode &= ~REWRITE_RECURSE; mode &= ~REWRITE_RECURSE;
@ -222,26 +229,24 @@ rewrite_rule_compile(
int *d; int *d;
if ( p[ 1 ] != '{' ) { if ( p[ 1 ] != '{' ) {
/* XXX Need to free stuff */ goto fail;
return REWRITE_ERR;
} }
d = malloc( sizeof( int ) ); d = malloc( sizeof( int ) );
if ( d == NULL ) { if ( d == NULL ) {
/* XXX Need to free stuff */ goto fail;
return REWRITE_ERR;
} }
d[ 0 ] = strtol( &p[ 2 ], &next, 0 ); d[ 0 ] = strtol( &p[ 2 ], &next, 0 );
if ( next == &p[ 2 ] || next[0] != '}' ) { if ( next == &p[ 2 ] || next[0] != '}' ) {
/* XXX Need to free stuff */ free( d );
return REWRITE_ERR; goto fail;
} }
action = calloc( sizeof( struct rewrite_action ), 1 ); action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) { if ( action == NULL ) {
/* cleanup ... */ free( d );
return REWRITE_ERR; goto fail;
} }
switch ( p[ 0 ] ) { switch ( p[ 0 ] ) {
case REWRITE_FLAG_GOTO: case REWRITE_FLAG_GOTO:
@ -270,14 +275,12 @@ rewrite_rule_compile(
char *next = NULL; char *next = NULL;
if ( p[ 1 ] != '{' ) { if ( p[ 1 ] != '{' ) {
/* XXX Need to free stuff */ goto fail;
return REWRITE_ERR;
} }
max_passes = strtol( &p[ 2 ], &next, 0 ); max_passes = strtol( &p[ 2 ], &next, 0 );
if ( next == &p[ 2 ] || next[0] != '}' ) { if ( next == &p[ 2 ] || next[0] != '}' ) {
/* XXX Need to free stuff */ goto fail;
return REWRITE_ERR;
} }
if ( max_passes < 1 ) { if ( max_passes < 1 ) {
@ -296,8 +299,7 @@ rewrite_rule_compile(
*/ */
action = calloc( sizeof( struct rewrite_action ), 1 ); action = calloc( sizeof( struct rewrite_action ), 1 );
if ( action == NULL ) { if ( action == NULL ) {
/* cleanup ... */ goto fail;
return REWRITE_ERR;
} }
action->la_type = REWRITE_ACTION_IGNORE_ERR; action->la_type = REWRITE_ACTION_IGNORE_ERR;
@ -327,23 +329,15 @@ rewrite_rule_compile(
*/ */
rule = calloc( sizeof( struct rewrite_rule ), 1 ); rule = calloc( sizeof( struct rewrite_rule ), 1 );
if ( rule == NULL ) { if ( rule == NULL ) {
/* charray_free( res ); */ goto fail;
/*
* XXX need to free the value subst stuff!
*/
return REWRITE_ERR;
} }
/* /*
* REGEX compilation (luckily I don't need to take care of this ...) * REGEX compilation (luckily I don't need to take care of this ...)
*/ */
if ( regcomp( &rule->lr_regex, ( char * )pattern, flags ) != 0 ) { if ( regcomp( &rule->lr_regex, ( char * )pattern, flags ) != 0 ) {
/* charray_free( res ); */
/*
*XXX need to free the value subst stuff!
*/
free( rule ); free( rule );
return REWRITE_ERR; goto fail;
} }
/* /*
@ -372,6 +366,11 @@ rewrite_rule_compile(
append_rule( context, rule ); append_rule( context, rule );
return REWRITE_SUCCESS; return REWRITE_SUCCESS;
fail:
destroy_actions( first_action );
free( subst );
return REWRITE_ERR;
} }
/* /*
@ -462,7 +461,6 @@ rewrite_rule_destroy(
) )
{ {
struct rewrite_rule *rule; struct rewrite_rule *rule;
struct rewrite_action *action;
assert( prule != NULL ); assert( prule != NULL );
assert( *prule != NULL ); assert( *prule != NULL );
@ -490,12 +488,7 @@ rewrite_rule_destroy(
regfree( &rule->lr_regex ); regfree( &rule->lr_regex );
for ( action = rule->lr_action; action; ) { destroy_actions( rule->lr_action );
struct rewrite_action *curraction = action;
action = action->la_next;
destroy_action( &curraction );
}
free( rule ); free( rule );
*prule = NULL; *prule = NULL;

View File

@ -214,7 +214,8 @@ rewrite_xmap_parse(
/* Unhandled map */ /* Unhandled map */
} }
free( map );
return NULL; return NULL;
} }