Blob Blame Raw
From 1ae1196e74d5bac16e63a9c453f88da9c28b5c4a Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Mon, 1 May 2017 14:52:48 -0400
Subject: [PATCH 09/22] efi_variable_import(): fix memory leak on failure path.

When one of our allocations fails, we leak the other one.  Woops.

Found by covscan.

Signed-off-by: Peter Jones <pjones@redhat.com>
---
 src/export.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/export.c b/src/export.c
index 7f2d4dd..89af720 100644
--- a/src/export.c
+++ b/src/export.c
@@ -96,11 +96,14 @@ efi_variable_import(uint8_t *data, size_t size, efi_variable_t **var_out)
 		ptr += sizeof (uint32_t);
 
 		if (name_len < 1 ||
-				name_len != ((data + size) - ptr - data_len))
-			return -1;
-		if (data_len < 1 ||
-				data_len != ((data + size) - ptr - name_len))
+		    name_len != ((data + size) - ptr - data_len) ||
+		    data_len < 1 ||
+		    data_len != ((data + size) - ptr - name_len)) {
+			int saved_errno = errno;
+			free(var.guid);
+			errno = saved_errno;
 			return -1;
+		}
 
 		var.name = calloc(1, name_len + 1);
 		if (!var.name) {
-- 
2.12.2