Patchwork lib: fwts_stringextras: handle out of memory failure

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

Comments

Colin King - March 2, 2012, 10:03 a.m.
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(-)
Keng-Yu Lin - March 5, 2012, 9:27 a.m.
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.
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>

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;