diff mbox

lib: fwts_tag: handle out of memory failure

Message ID 1330682462-18287-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King March 2, 2012, 10:01 a.m. UTC
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(-)

Comments

Keng-Yu Lin March 5, 2012, 9:04 a.m. UTC | #1
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. UTC | #2
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>
diff mbox

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);
 		}
 	}