Patchwork lib: fwts_tag: handle out of memory failure

login
register
mail settings
Submitter Colin King
Date March 2, 2012, 10:01 a.m.
Message ID <1330682462-18287-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/144187/
State Accepted
Headers show

Comments

Colin King - March 2, 2012, 10:01 a.m.
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_tag.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
Keng-Yu Lin - March 5, 2012, 9:04 a.m.
On Fri, Mar 2, 2012 at 6:01 PM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_tag.c |    6 ++++--
>  1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_tag.c b/src/lib/src/fwts_tag.c
> index 76c84ec..24e0b53 100644
> --- a/src/lib/src/fwts_tag.c
> +++ b/src/lib/src/fwts_tag.c
> @@ -158,11 +158,13 @@ char *fwts_tag_list_to_str(fwts_list *taglist)
>                len += taglen + 1;
>
>                if (str) {
> -                       str = realloc(str, len);
> +                       if ((str = realloc(str, len)) == NULL)
> +                               return NULL;
>                        strcat(str, " ");
>                        strcat(str, tag);
>                } else {
> -                       str = malloc(len);
> +                       if ((str = malloc(len)) == NULL)
> +                               return NULL;
>                        strcpy(str, tag);
>                }
>        }
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung - March 7, 2012, 9:52 a.m.
On 03/02/2012 06:01 PM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/lib/src/fwts_tag.c |    6 ++++--
>   1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/src/fwts_tag.c b/src/lib/src/fwts_tag.c
> index 76c84ec..24e0b53 100644
> --- a/src/lib/src/fwts_tag.c
> +++ b/src/lib/src/fwts_tag.c
> @@ -158,11 +158,13 @@ char *fwts_tag_list_to_str(fwts_list *taglist)
>   		len += taglen + 1;
>
>   		if (str) {
> -			str = realloc(str, len);
> +			if ((str = realloc(str, len)) == NULL)
> +				return NULL;
>   			strcat(str, " ");
>   			strcat(str, tag);
>   		} else {
> -			str = malloc(len);
> +			if ((str = malloc(len)) == NULL)
> +				return NULL;
>   			strcpy(str, tag);
>   		}
>   	}
Acked-by: Alex Hung <alex.hung@canonical.com>

Patch

diff --git a/src/lib/src/fwts_tag.c b/src/lib/src/fwts_tag.c
index 76c84ec..24e0b53 100644
--- a/src/lib/src/fwts_tag.c
+++ b/src/lib/src/fwts_tag.c
@@ -158,11 +158,13 @@  char *fwts_tag_list_to_str(fwts_list *taglist)
 		len += taglen + 1;
 
 		if (str) {
-			str = realloc(str, len);
+			if ((str = realloc(str, len)) == NULL)
+				return NULL;
 			strcat(str, " ");
 			strcat(str, tag);
 		} else {
-			str = malloc(len);
+			if ((str = malloc(len)) == NULL)
+				return NULL;
 			strcpy(str, tag);
 		}
 	}