Unload prio and checkers libraries during shutdown.
authorKonrad Rzeszutek <konrad@virtualiron.com>
Tue, 24 Mar 2009 18:01:05 +0000 (19:01 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 24 Mar 2009 18:01:05 +0000 (19:01 +0100)
Our statup sequence is 'load_config', 'init_checkers', and 'init_prio'.
Both init_* functions reset the list of prio and checkers, which is
unfortunate as in load_config, depending on the multipat.conf, would
load prio and checker libraries. This results in double-loading of
the libraries and a memory leak.

libmultipath/checkers.c
libmultipath/checkers.h
libmultipath/prio.c
libmultipath/prio.h
multipath/main.c
multipathd/main.c

index 5132081..19d0781 100644 (file)
@@ -27,7 +27,6 @@ char * checker_state_name (int i)
 
 int init_checkers (void)
 {
-       INIT_LIST_HEAD(&checkers);
        if (!add_checker(DEFAULT_CHECKER))
                return 1;
        return 0;
@@ -35,12 +34,12 @@ int init_checkers (void)
 
 struct checker * alloc_checker (void)
 {
-       return zalloc(sizeof(struct checker));
+       return MALLOC(sizeof(struct checker));
 }
 
 void free_checker (struct checker * c)
 {
-       free(c);
+       FREE(c);
 }
 
 void cleanup_checkers (void)
@@ -50,7 +49,7 @@ void cleanup_checkers (void)
 
        list_for_each_entry_safe(checker_loop, checker_temp, &checkers, node) {
                list_del(&checker_loop->node);
-               free(checker_loop);
+               free_checker(checker_loop);
        }
 }
 
index a9bc6a6..6ba0339 100644 (file)
@@ -112,6 +112,7 @@ struct checker {
 
 char * checker_state_name (int);
 int init_checkers (void);
+void cleanup_checkers (void);
 struct checker * add_checker (char *);
 struct checker * checker_lookup (char *);
 int checker_init (struct checker *, void **);
index c9d2873..4c5f4f0 100644 (file)
@@ -11,7 +11,6 @@ static LIST_HEAD(prioritizers);
 
 int init_prio (void)
 {
-       INIT_LIST_HEAD(&prioritizers);
        if (!add_prio(DEFAULT_PRIO))
                return 1;
        return 0;
@@ -19,12 +18,12 @@ int init_prio (void)
 
 struct prio * alloc_prio (void)
 {
-       return zalloc(sizeof(struct prio));
+       return MALLOC(sizeof(struct prio));
 }
 
 void free_prio (struct prio * p)
 {
-       free(p);
+       FREE(p);
 }
 
 void cleanup_prio(void)
@@ -34,7 +33,7 @@ void cleanup_prio(void)
 
        list_for_each_entry_safe(prio_loop, prio_temp, &prioritizers, node) {
                list_del(&prio_loop->node);
-               free(prio_loop);
+               free_prio(prio_loop);
        }
 }
 
index 491e6fc..fc9277f 100644 (file)
@@ -42,6 +42,7 @@ struct prio {
 };
 
 int init_prio (void);
+void cleanup_prio (void);
 struct prio * add_prio (char *);
 struct prio * prio_lookup (char *);
 int prio_getprio (struct prio *, struct path *);
index 2f227d1..1fee475 100644 (file)
@@ -444,6 +444,8 @@ out:
        dm_lib_release();
        dm_lib_exit();
 
+       cleanup_prio();
+       cleanup_checkers();
        /*
         * Freeing config must be done after dm_lib_exit(), because
         * the logging function (dm_write_log()), which is called there,
index 7d2316a..996bd9d 100644 (file)
@@ -1395,6 +1395,8 @@ child (void * param)
        dm_lib_release();
        dm_lib_exit();
 
+       cleanup_prio();
+       cleanup_checkers();
        /*
         * Freeing config must be done after condlog() and dm_lib_exit(),
         * because logging functions like dlog() and dm_write_log()