[PATCH] bios: mtrr: handle out of memory failures

Colin King colin.king at canonical.com
Fri Mar 2 10:20:37 UTC 2012


From: Colin Ian King <colin.king at canonical.com>

Signed-off-by: Colin Ian King <colin.king at canonical.com>
---
 src/bios/mtrr/mtrr.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c
index f94a465..4ab742d 100644
--- a/src/bios/mtrr/mtrr.c
+++ b/src/bios/mtrr/mtrr.c
@@ -205,6 +205,11 @@ static fwts_list *get_klog_bios_mtrr(void)
 					struct mtrr_entry *mtrr;
 
 					mtrr = calloc(1, sizeof(struct mtrr_entry));
+					if (mtrr == NULL) {
+						fwts_list_free(mtrr_bios_list,
+							free);
+						return NULL;
+					}
 					mtrr->type = 0;
 
 					uint64_t mask =
@@ -240,8 +245,10 @@ static int check_vga_controller_address(fwts_framework *fw)
 
 	memset(line,0,4096);
 
-	if ((mtrr_bios_list = get_klog_bios_mtrr()) == NULL)
+	if ((mtrr_bios_list = get_klog_bios_mtrr()) == NULL) {
+		fwts_log_error("Out of memory fetching MTRR list.");
 		return FWTS_ERROR;
+	}
 
 	snprintf(line, sizeof(line), "%s -v", fw->lspci);
 	fwts_pipe_exec(line, &lspci_output);
-- 
1.7.9





More information about the fwts-devel mailing list