diff mbox

[01/10] lib: fwts_acpi_tables: fix memory leak on error exit path

Message ID 1398952881-27828-2-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 1, 2014, 2:01 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Forgot to free the hdr if the hdr length is too small.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_acpi_tables.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Comments

Ivan Hu May 6, 2014, 2:49 a.m. UTC | #1
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Forgot to free the hdr if the hdr length is too small.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_acpi_tables.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index e40583e..d6ab1ce 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -172,8 +172,10 @@ static void *fwts_acpi_load_table(const off_t addr)
>   		return NULL;
>
>   	len = hdr->length;
> -	if (len < (int)sizeof(fwts_acpi_table_header))
> +	if (len < (int)sizeof(fwts_acpi_table_header)) {
> +		(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));
>   		return NULL;
> +	}
>
>   	(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));
>
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>
Alex Hung May 6, 2014, 8:25 a.m. UTC | #2
On 05/01/2014 10:01 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Forgot to free the hdr if the hdr length is too small.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_acpi_tables.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index e40583e..d6ab1ce 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -172,8 +172,10 @@ static void *fwts_acpi_load_table(const off_t addr)
>   		return NULL;
>
>   	len = hdr->length;
> -	if (len < (int)sizeof(fwts_acpi_table_header))
> +	if (len < (int)sizeof(fwts_acpi_table_header)) {
> +		(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));
>   		return NULL;
> +	}
>
>   	(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));
>
>

Acked-by: Alex Hung <alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index e40583e..d6ab1ce 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -172,8 +172,10 @@  static void *fwts_acpi_load_table(const off_t addr)
 		return NULL;
 
 	len = hdr->length;
-	if (len < (int)sizeof(fwts_acpi_table_header))
+	if (len < (int)sizeof(fwts_acpi_table_header)) {
+		(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));
 		return NULL;
+	}
 
 	(void)fwts_munmap(hdr, sizeof(fwts_acpi_table_header));