From 16ce182c1810e352fba5a1a33d1223583255e5dd Mon Sep 17 00:00:00 2001 From: elliotkendall <elliotkendall@gmail.com> Date: Fri, 6 Jun 2014 12:58:23 -0700 Subject: [PATCH] Check for failure of realloc --- fanout.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/fanout.c b/fanout.c index 9af474f..c906d66 100644 --- a/fanout.c +++ b/fanout.c @@ -677,6 +677,8 @@ void str_swap_free (char **target, char *source) char *str_append (char *target, const char *data) { + char *newtarget; + if (data == NULL) { return target; } @@ -687,9 +689,14 @@ char *str_append (char *target, const char *data) } int len = strlen (target) + strlen (data) + 1; - target = realloc (target, len); + newtarget = realloc (target, len); + if (newtarget == NULL) { + fanout_error ("ERROR unable to allocate memory"); + exit (EXIT_FAILURE); + } + newtarget = strcat (newtarget, data); - return strcat (target, data); + return newtarget; } -- GitLab