[PATCH 04/42] libmultipath: resource leak in read_value_block()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



read_value_block() allocates the vector 'elements', but
doesn't free it on error.

Signed-off-by: Hannes Reinecke <hare@xxxxxxx>
---
 libmultipath/parser.c |   32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diff --git a/libmultipath/parser.c b/libmultipath/parser.c
index 79c2d22..526c45b 100644
--- a/libmultipath/parser.c
+++ b/libmultipath/parser.c
@@ -311,8 +311,10 @@ read_value_block(void)
 
 	buf = (char *) MALLOC(MAXBUF);
 
-	if (!buf)
+	if (!buf) {
+		vector_free(elements);
 		return NULL;
+	}
 
 	while (read_line(buf, MAXBUF)) {
 		vec = alloc_strvec(buf);
@@ -323,21 +325,20 @@ read_value_block(void)
 				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);
@@ -348,6 +349,7 @@ out1:
 	FREE(dup);
 out:
 	FREE(buf);
+	vector_free(elements);
 	return NULL;
 }
 
-- 
1.7.4.2

--
dm-devel mailing list
dm-devel@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/dm-devel


[Index of Archives]     [DM Crypt]     [Fedora Desktop]     [ATA RAID]     [Fedora Marketing]     [Fedora Packaging]     [Fedora SELinux]     [Yosemite Discussion]     [KDE Users]     [Fedora Docs]

  Powered by Linux