[lib] Substantial memory leak when large amount of LUNs are present
authorKonrad Rzeszutek <konrad@virtualiron.com>
Wed, 17 Dec 2008 22:19:19 +0000 (23:19 +0100)
committerChristophe Varoqui <christophe.varoqui@free.fr>
Wed, 17 Dec 2008 22:19:19 +0000 (23:19 +0100)
dm_get_name() was creating a vector, populating it with multipaths,
then only deleting the vector itself, which leaked all of the multipaths.
If the number of LUNs (ie. multipaths) was large then the leak was equally large.

Signed-off-by: Konrad Rzeszutek <konrad@virtualiron.com>
libmultipath/devmapper.c

index 70e10c2..a021e44 100644 (file)
@@ -764,7 +764,7 @@ dm_get_name(char *uuid, char *name)
 {
        vector vec;
        struct multipath *mpp;
-       int i;
+       int i, rc = 0;
 
        vec = vector_alloc();
 
@@ -772,20 +772,22 @@ dm_get_name(char *uuid, char *name)
                return 0;
 
        if (dm_get_maps(vec)) {
-               vector_free(vec);
-               return 0;
+               goto out;
        }
 
        vector_foreach_slot(vec, mpp, i) {
                if (!strcmp(uuid, mpp->wwid)) {
-                       vector_free(vec);
                        strcpy(name, mpp->alias);
-                       return 1;
+                       rc=1;
+                       break;
                }
        }
-
+out:
+       vector_foreach_slot(vec, mpp, i) {
+               free_multipath(mpp, KEEP_PATHS);
+       }
        vector_free(vec);
-       return 0;
+       return rc;
 }
 
 int