From fd1c54180274d931b8102aadbaaf790c97cf8d07 Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Fri, 14 Oct 2016 09:35:16 +0300 Subject: Check if allocation failed --- source/common/acfileio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/common/acfileio.c b/source/common/acfileio.c index 6cb953633..3f2fcd9ea 100644 --- a/source/common/acfileio.c +++ b/source/common/acfileio.c @@ -242,6 +242,11 @@ AcGetAllTablesFromFile ( /* Allocate and link a table descriptor */ TableDesc = AcpiOsAllocate (sizeof (ACPI_NEW_TABLE_DESC)); + if (!TableDesc) + { + Status = AE_NO_MEMORY; + goto ErrorExit; + } TableDesc->Table = Table; TableDesc->Next = NULL; -- cgit v1.2.1 From 2cbca1d93ac618de4dd6cfde2a96895ad1338eaf Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Fri, 14 Oct 2016 09:18:56 +0300 Subject: Rename ErrorExit to Exit. We always want to end up here, to close fd, not just on error. --- source/common/acfileio.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/source/common/acfileio.c b/source/common/acfileio.c index 3f2fcd9ea..2d71f7966 100644 --- a/source/common/acfileio.c +++ b/source/common/acfileio.c @@ -184,7 +184,7 @@ AcGetAllTablesFromFile ( if (FileSize == ACPI_UINT32_MAX) { Status = AE_ERROR; - goto ErrorExit; + goto Exit; } fprintf (stderr, @@ -196,7 +196,7 @@ AcGetAllTablesFromFile ( if (FileSize < sizeof (ACPI_TABLE_HEADER)) { Status = AE_BAD_HEADER; - goto ErrorExit; + goto Exit; } /* Check for an non-binary file */ @@ -229,7 +229,7 @@ AcGetAllTablesFromFile ( } else if (ACPI_FAILURE (Status)) { - goto ErrorExit; + goto Exit; } /* Print table header for iASL/disassembler only */ @@ -245,7 +245,7 @@ AcGetAllTablesFromFile ( if (!TableDesc) { Status = AE_NO_MEMORY; - goto ErrorExit; + goto Exit; } TableDesc->Table = Table; TableDesc->Next = NULL; @@ -281,7 +281,7 @@ AcGetAllTablesFromFile ( *ReturnListHead = ListHead; } -ErrorExit: +Exit: fclose(File); return (Status); } -- cgit v1.2.1 From b0f2f96693b0f2fd95601f1c68cf06f2167ecf6e Mon Sep 17 00:00:00 2001 From: Maya Rashish Date: Fri, 14 Oct 2016 09:21:34 +0300 Subject: All paths lead to Exit (and closing fd) Avoid resource leak on some paths --- source/common/acfileio.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/common/acfileio.c b/source/common/acfileio.c index 2d71f7966..8af52d117 100644 --- a/source/common/acfileio.c +++ b/source/common/acfileio.c @@ -206,7 +206,8 @@ AcGetAllTablesFromFile ( fprintf (stderr, " %s: File does not appear to contain a valid AML table\n", Filename); - return (AE_TYPE); + Status = AE_TYPE; + goto Exit; } /* Read all tables within the file */ @@ -225,7 +226,8 @@ AcGetAllTablesFromFile ( } else if (Status == AE_TYPE) { - return (AE_OK); + Status = AE_OK; + goto Exit; } else if (ACPI_FAILURE (Status)) { -- cgit v1.2.1