diff mbox

lib: fwts_stringextras: handle out of memory failure

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

Commit Message

Colin Ian King March 2, 2012, 10:03 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_stringextras.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)

Comments

Keng-Yu Lin March 5, 2012, 9:27 a.m. UTC | #1
On Fri, Mar 2, 2012 at 6:03 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_stringextras.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/src/lib/src/fwts_stringextras.c b/src/lib/src/fwts_stringextras.c
> index df0608d..babf2ed 100644
> --- a/src/lib/src/fwts_stringextras.c
> +++ b/src/lib/src/fwts_stringextras.c
> @@ -54,7 +54,8 @@ char *fwts_realloc_strcat(char *orig, const char *newstr)
>                        return NULL;
>                strcat(orig, newstr);
>        } else {
> -               orig = malloc(newlen + 1);
> +               if ((orig = malloc(newlen + 1)) == NULL)
> +                       return NULL;
>                strcpy(orig, newstr);
>        }
>        return orig;
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
Alex Hung March 7, 2012, 2:56 a.m. UTC | #2
On Fri, Mar 2, 2012 at 6:03 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_stringextras.c |    3 ++-
>   1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/src/lib/src/fwts_stringextras.c b/src/lib/src/fwts_stringextras.c
> index df0608d..babf2ed 100644
> --- a/src/lib/src/fwts_stringextras.c
> +++ b/src/lib/src/fwts_stringextras.c
> @@ -54,7 +54,8 @@ char *fwts_realloc_strcat(char *orig, const char *newstr)
>                         return NULL;
>                 strcat(orig, newstr);
>         } else {
> -               orig = malloc(newlen + 1);
> +               if ((orig = malloc(newlen + 1)) == NULL)
> +                       return NULL;
>                 strcpy(orig, newstr);
>         }
>         return orig;
> --
> 1.7.9
>
Acked-by: Alex Hung<alex.hung@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_stringextras.c b/src/lib/src/fwts_stringextras.c
index df0608d..babf2ed 100644
--- a/src/lib/src/fwts_stringextras.c
+++ b/src/lib/src/fwts_stringextras.c
@@ -54,7 +54,8 @@  char *fwts_realloc_strcat(char *orig, const char *newstr)
 			return NULL;
 		strcat(orig, newstr);
 	} else {
-		orig = malloc(newlen + 1);
+		if ((orig = malloc(newlen + 1)) == NULL)
+			return NULL;
 		strcpy(orig, newstr);
 	}
 	return orig;