libmultipath: resource leak in read_value_block()
authorHannes Reinecke <hare@suse.de>
Tue, 8 Jan 2013 13:53:42 +0000 (14:53 +0100)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Tue, 8 Jan 2013 22:19:32 +0000 (23:19 +0100)
read_value_block() allocates the vector 'elements', but
doesn't free it on error.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/parser.c

index 79c2d22..526c45b 100644 (file)
@@ -311,8 +311,10 @@ read_value_block(void)
 
        buf = (char *) MALLOC(MAXBUF);
 
 
        buf = (char *) MALLOC(MAXBUF);
 
-       if (!buf)
+       if (!buf) {
+               vector_free(elements);
                return NULL;
                return NULL;
+       }
 
        while (read_line(buf, MAXBUF)) {
                vec = alloc_strvec(buf);
 
        while (read_line(buf, MAXBUF)) {
                vec = alloc_strvec(buf);
@@ -323,21 +325,20 @@ read_value_block(void)
                                break;
                        }
 
                                break;
                        }
 
-                       if (VECTOR_SIZE(vec))
-                               for (i = 0; i < VECTOR_SIZE(vec); i++) {
-                                       str = VECTOR_SLOT(vec, i);
-                                       dup = (char *) MALLOC(strlen(str) + 1);
-                                       if (!dup)
-                                               goto out;
-                                       memcpy(dup, str, strlen(str));
-
-                                       if (!vector_alloc_slot(elements)) {
-                                               free_strvec(vec);
-                                               goto out1;
-                                       }
+                       for (i = 0; i < VECTOR_SIZE(vec); i++) {
+                               str = VECTOR_SLOT(vec, i);
+                               dup = (char *) MALLOC(strlen(str) + 1);
+                               if (!dup)
+                                       goto out;
+                               memcpy(dup, str, strlen(str));
 
 
-                                       vector_set_slot(elements, dup);
+                               if (!vector_alloc_slot(elements)) {
+                                       free_strvec(vec);
+                                       goto out1;
                                }
                                }
+
+                               vector_set_slot(elements, dup);
+                       }
                        free_strvec(vec);
                }
                memset(buf, 0, MAXBUF);
                        free_strvec(vec);
                }
                memset(buf, 0, MAXBUF);
@@ -348,6 +349,7 @@ out1:
        FREE(dup);
 out:
        FREE(buf);
        FREE(dup);
 out:
        FREE(buf);
+       vector_free(elements);
        return NULL;
 }
 
        return NULL;
 }