filter.c: Handle filter errors gracefully.
authorAndre Noll <maan@systemlinux.org>
Sun, 20 Apr 2008 18:55:15 +0000 (20:55 +0200)
committerAndre Noll <maan@systemlinux.org>
Sun, 20 Apr 2008 18:55:15 +0000 (20:55 +0200)
Free the filter chain struct on errors and do not try to
close filters that haven't been opened.

filter.c

index ed168c3..1620439 100644 (file)
--- a/filter.c
+++ b/filter.c
@@ -75,7 +75,7 @@ static int init_filter_chain(void)
                fn = fc->filter_nodes + i;
                ret = check_filter_arg(fa, &fn->conf);
                if (ret < 0)
-                       return ret;
+                       goto err;
                fn->filter_num = ret;
                fn->fc = fc;
                INIT_LIST_HEAD(&fn->callbacks);
@@ -83,6 +83,9 @@ static int init_filter_chain(void)
        }
        open_filters();
        return 1;
+err:
+       free(fc->filter_nodes);
+       return ret;
 }
 
 static int parse_config(int argc, char *argv[])
@@ -159,9 +162,9 @@ int main(int argc, char *argv[])
        s.default_timeout.tv_sec = 1;
        s.default_timeout.tv_usec = 0;
        ret = schedule(&s);
+       close_filters(fc);
 out:
        free(sit->buf);
-       close_filters(fc);
        if (ret < 0)
                PARA_EMERG_LOG("%s\n", para_strerror(-ret));
        return ret < 0? EXIT_FAILURE : EXIT_SUCCESS;