]> git.sur5r.net Git - openldap/commitdiff
plug leaks
authorHoward Chu <hyc@openldap.org>
Fri, 31 Mar 2006 20:06:49 +0000 (20:06 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 31 Mar 2006 20:06:49 +0000 (20:06 +0000)
libraries/librewrite/config.c
libraries/librewrite/rule.c
libraries/librewrite/xmap.c

index a8ca8cc71d9ec8ce0cfd9b634e3da20c929b7d53..3cbd1f73e76d928d689db9fbc282c14cbef5cec5 100644 (file)
@@ -431,6 +431,7 @@ rewrite_parse_builtin_map(
         * Error
         */     
        } else {
+               free( map );
                Debug( LDAP_DEBUG_ANY, "[%s:%d] unknown map type\n%s",
                                fname, lineno, "" );
                return -1;
index 9659b11722c79d617df86ad730e7cb4ccb3e0d48..4964ef0a6c5abf2fa11d6cf0e913710bed5448ae 100644 (file)
@@ -99,11 +99,20 @@ destroy_action(
        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
 rewrite_rule_compile(
@@ -186,8 +195,7 @@ rewrite_rule_compile(
                         */
                        action = calloc( sizeof( struct rewrite_action ), 1 );
                        if ( action == NULL ) {
-                               /* cleanup ... */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
 
                        action->la_type = REWRITE_ACTION_STOP;
@@ -199,8 +207,7 @@ rewrite_rule_compile(
                         */
                        action = calloc( sizeof( struct rewrite_action ), 1 );
                        if ( action == NULL ) {
-                               /* cleanup ... */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
                        
                        mode &= ~REWRITE_RECURSE;
@@ -222,26 +229,24 @@ rewrite_rule_compile(
                        int *d;
                        
                        if ( p[ 1 ] != '{' ) {
-                               /* XXX Need to free stuff */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
 
                        d = malloc( sizeof( int ) );
                        if ( d == NULL ) {
-                               /* XXX Need to free stuff */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
 
                        d[ 0 ] = strtol( &p[ 2 ], &next, 0 );
                        if ( next == &p[ 2 ] || next[0] != '}' ) {
-                               /* XXX Need to free stuff */
-                               return REWRITE_ERR;
+                               free( d );
+                               goto fail;
                        }
 
                        action = calloc( sizeof( struct rewrite_action ), 1 );
                        if ( action == NULL ) {
-                               /* cleanup ... */       
-                               return REWRITE_ERR;
+                               free( d );
+                               goto fail;
                        }
                        switch ( p[ 0 ] ) {
                        case REWRITE_FLAG_GOTO:
@@ -270,14 +275,12 @@ rewrite_rule_compile(
                        char *next = NULL;
                        
                        if ( p[ 1 ] != '{' ) {
-                               /* XXX Need to free stuff */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
 
                        max_passes = strtol( &p[ 2 ], &next, 0 );
                        if ( next == &p[ 2 ] || next[0] != '}' ) {
-                               /* XXX Need to free stuff */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
 
                        if ( max_passes < 1 ) {
@@ -296,8 +299,7 @@ rewrite_rule_compile(
                         */
                        action = calloc( sizeof( struct rewrite_action ), 1 );
                        if ( action == NULL ) {
-                               /* cleanup ... */
-                               return REWRITE_ERR;
+                               goto fail;
                        }
                        
                        action->la_type = REWRITE_ACTION_IGNORE_ERR;
@@ -327,23 +329,15 @@ rewrite_rule_compile(
         */
        rule = calloc( sizeof( struct rewrite_rule ), 1 );
        if ( rule == NULL ) {
-               /* charray_free( res ); */
-               /*
-                * XXX need to free the value subst stuff!
-                */
-               return REWRITE_ERR;
+               goto fail;
        }
        
        /*
         * REGEX compilation (luckily I don't need to take care of this ...)
         */
        if ( regcomp( &rule->lr_regex, ( char * )pattern, flags ) != 0 ) {
-               /* charray_free( res ); */
-               /*
-                *XXX need to free the value subst stuff!
-                */
                free( rule );
-               return REWRITE_ERR;
+               goto fail;
        }
        
        /*
@@ -372,6 +366,11 @@ rewrite_rule_compile(
        append_rule( context, rule );
 
        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_action *action;
 
        assert( prule != NULL );
        assert( *prule != NULL );
@@ -490,12 +488,7 @@ 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 );
-       }
+       destroy_actions( rule->lr_action );
 
        free( rule );
        *prule = NULL;
index fbc73d0bf4050d9011c9535128d42adfb843d56d..d0d0874f7115d39f504fc6dd147d5b1e8b832415 100644 (file)
@@ -214,7 +214,8 @@ rewrite_xmap_parse(
        
        /* Unhandled map */
        }
-       
+
+       free( map );
        return NULL;
 }