From c834ba6a71f67dad02cee4211782cec6b7dc6348 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sat, 11 Nov 2006 19:40:41 +0000 Subject: [PATCH] let's make sure realloc works git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3316 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/switch_event.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/switch_event.c b/src/switch_event.c index 278230b62b..fdc1a9eb3d 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -615,8 +615,14 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch llen = strlen(hp->name) + strlen(hp->value) + 2; if ((len + llen) > dlen) { + char *m; dlen += (blocksize + (len + llen)); - buf = realloc(buf, dlen); + if ((m = realloc(buf, dlen))) { + buf = m; + } else { + switch_safe_free(buf); + return SWITCH_STATUS_MEMERR; + } } snprintf(buf + len, dlen - len, "%s: %s\n", hp->name, hp->value); @@ -634,10 +640,16 @@ SWITCH_DECLARE(switch_status_t) switch_event_serialize(switch_event_t *event, ch } if ((len + llen) > dlen) { + char *m; dlen += (blocksize + (len + llen)); - buf = realloc(buf, dlen); + if ((m = realloc(buf, dlen))) { + buf = m; + } else { + switch_safe_free(buf); + return SWITCH_STATUS_MEMERR; + } } - + if (blen) { snprintf(buf + len, dlen - len, "Content-Length: %d\n\n%s", blen, event->body); } else {