From: Andrey Volk Date: Fri, 6 Sep 2019 14:01:55 +0000 (+0400) Subject: FS-12040: [mod_sofia] Fix potential leak if realloc fails. X-Git-Tag: v1.10.2^2~107^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ee53a6ec1753204d5f17e1f7d2b9429b8ab1342;p=thirdparty%2Ffreeswitch.git FS-12040: [mod_sofia] Fix potential leak if realloc fails. --- diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 0b0b1b82a0..6e4727d51c 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -821,8 +821,13 @@ void sofia_handle_sip_i_notify(switch_core_session_t *session, int status, while ((call_info = call_info->ci_next) != NULL) { char *tmp = sip_header_as_string(nua_handle_home(nh), (void *) call_info); size_t tmp_len = strlen(tmp); - hold = realloc(hold, cur_len + tmp_len + 2); - switch_assert(hold); + char *tmp_hold = realloc(hold, cur_len + tmp_len + 2); + if (!tmp_hold) { + /* Avoid leak if realloc failed */ + free(hold); + } + switch_assert(tmp_hold); + hold = tmp_hold; strncpy(hold + cur_len, ",", 2); strncpy(hold + cur_len + 1, tmp, tmp_len +1); su_free(nua_handle_home(nh), tmp);