Plug memory leaks
authorHannes Reinecke <hare@suse.de>
Wed, 28 Jan 2009 08:24:10 +0000 (09:24 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Tue, 21 Apr 2009 23:34:57 +0000 (01:34 +0200)
Running the internal memory checker revealed quite some memory
leaks.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/blacklist.c
libmultipath/config.c
libmultipath/devmapper.c
libmultipath/dmparser.c
libmultipath/parser.c
libmultipath/structs.c
libmultipath/structs_vec.c
multipathd/cli.c

index 7db43c6..f369517 100644 (file)
@@ -51,10 +51,10 @@ alloc_ble_device (vector blist)
 {
        struct blentry_device * ble = MALLOC(sizeof(struct blentry_device));
 
-       if (!ble || !blist)
+       if (!ble)
                return 1;
 
-       if (!vector_alloc_slot(blist)) {
+       if (!blist || !vector_alloc_slot(blist)) {
                FREE(ble);
                return 1;
        }
@@ -70,7 +70,7 @@ set_ble_device (vector blist, char * vendor, char * product, int origin)
        if (!blist)
                return 1;
 
-       ble = VECTOR_SLOT(blist, VECTOR_SIZE(blist) - 1);
+       ble = VECTOR_LAST_SLOT(blist);
 
        if (!ble)
                return 1;
@@ -345,10 +345,14 @@ free_blacklist_device (vector blist)
 
        vector_foreach_slot (blist, ble, i) {
                if (ble) {
-                       regfree(&ble->vendor_reg);
-                       regfree(&ble->product_reg);
-                       FREE(ble->vendor);
-                       FREE(ble->product);
+                       if (ble->vendor) {
+                               regfree(&ble->vendor_reg);
+                               FREE(ble->vendor);
+                       }
+                       if (ble->product) {
+                               regfree(&ble->product_reg);
+                               FREE(ble->product);
+                       }
                        FREE(ble);
                }
        }
index 6039642..1cb0b6c 100644 (file)
@@ -155,6 +155,9 @@ free_hwe (struct hwentry * hwe)
        if (hwe->prio_name)
                FREE(hwe->prio_name);
 
+       if (hwe->prio_arg)
+               FREE(hwe->prio_arg);
+
        if (hwe->bl_product)
                FREE(hwe->bl_product);
 
index 394f1ec..0048ed0 100644 (file)
@@ -995,8 +995,11 @@ dm_get_info (char * mapname, struct dm_info ** dmi)
 
        r = 0;
 out:
-       if (r)
+       if (r) {
                memset(*dmi, 0, sizeof(struct dm_info));
+               FREE(*dmi);
+               *dmi = NULL;
+       }
 
        if (dmt)
                dm_task_destroy(dmt);
index 09c90a8..c2f5af7 100644 (file)
@@ -189,7 +189,8 @@ disassemble_map (vector pathvec, char * params, struct multipath * mpp)
 
                if (!mpp->pg)
                        return 1;
-       }
+       } else
+               mpp->pg = NULL;
 
        /*
         * first pg to try
@@ -283,7 +284,7 @@ disassemble_map (vector pathvec, char * params, struct multipath * mpp)
 
                                /* Only call this in multipath client mode */
                                if (!mpp->waiter && store_path(pathvec, pp))
-                                       goto out;
+                                       goto out1;
                        }
                        FREE(word);
 
index f1fdeb8..6e42590 100644 (file)
@@ -326,8 +326,10 @@ read_value_block(void)
                                        dup = (char *) MALLOC(strlen(str) + 1);
                                        memcpy(dup, str, strlen(str));
 
-                                       if (!vector_alloc_slot(elements))
+                                       if (!vector_alloc_slot(elements)) {
+                                               free_strvec(vec);
                                                goto out1;
+                                       }
 
                                        vector_set_slot(elements, dup);
                                }
index bb0d9f7..a4b86d2 100644 (file)
@@ -79,8 +79,10 @@ alloc_pathgroup (void)
 
        pgp->paths = vector_alloc();
 
-       if (!pgp->paths)
+       if (!pgp->paths) {
                FREE(pgp);
+               pgp = NULL;
+       }
 
        return pgp;
 }
@@ -168,8 +170,10 @@ free_multipath (struct multipath * mpp, int free_paths)
                mpp->alias = NULL;
        }
 
-       if (mpp->dmi)
+       if (mpp->dmi) {
                FREE(mpp->dmi);
+               mpp->dmi = NULL;
+       }
 
        /*
         * better own vecs->lock here
index 8051b99..699efa1 100644 (file)
@@ -271,6 +271,7 @@ extern int
 update_multipath_strings (struct multipath *mpp, vector pathvec)
 {
        condlog(4, "%s: %s", mpp->alias, __FUNCTION__);
+
        free_multipath_attributes(mpp);
        free_pgvec(mpp->pg, KEEP_PATHS);
        mpp->pg = NULL;
@@ -384,8 +385,10 @@ add_map_without_path (struct vectors * vecs,
 
        mpp->alias = alias;
 
-       if (setup_multipath(vecs, mpp))
+       if (setup_multipath(vecs, mpp)) {
+               mpp->alias = NULL;
                return NULL; /* mpp freed in setup_multipath */
+       }
 
        if (adopt_paths(vecs->pathvec, mpp))
                goto out;
index 923529c..208a0ad 100644 (file)
@@ -233,8 +233,10 @@ get_cmdvec (char * cmd, vector *v)
        cmdvec = vector_alloc();
        *v = cmdvec;
 
-       if (!cmdvec)
+       if (!cmdvec) {
+               free_strvec(strvec);
                return E_NOMEM;
+       }
 
        vector_foreach_slot(strvec, buff, i) {
                if (*buff == '"')
@@ -269,6 +271,7 @@ get_cmdvec (char * cmd, vector *v)
                r = E_NOPARM;
                goto out;
        }
+       free_strvec(strvec);
        return 0;
 
 out:
@@ -377,6 +380,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data)
        if (!h) {
                *reply = genhelp_handler();
                *len = strlen(*reply) + 1;
+               free_keys(cmdvec);
                return 0;
        }