From 3ebeabfdafd141d112c76faeac604256b231ffd0 Mon Sep 17 00:00:00 2001 From: Bogdan-Andrei Iancu Date: Tue, 3 Dec 2019 18:05:43 +0200 Subject: [PATCH] Pre-allocate the str holder for the CT body for build_notify_body_t --- modules/presence/event_list.h | 5 +++-- modules/presence/notify.c | 10 +++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/modules/presence/event_list.h b/modules/presence/event_list.h index ebd7243b14..9dead24f60 100644 --- a/modules/presence/event_list.h +++ b/modules/presence/event_list.h @@ -76,8 +76,9 @@ typedef int (get_rules_doc_t)(str* user, str* domain, str** rules_doc); * Input data: presentity SIP URI and the SUBSCRIBE's body * Output data: * the body (may be empty string if nothing to return); it must * be a pkg allocated str and separate pkg allocated body - * * the content-type string - must be a single pkg mem chunk - * holding the str and the CT body also + * * the content-type string - must be a pkg mem chunk + * holding the CT body; note that the str itself is managed by + * the upper/calling layer, so just use/write into it. * Returns : body str upon success, NULL upon error */ typedef str* (build_notify_body_t)(str *pres_uri, str *subs_body, diff --git a/modules/presence/notify.c b/modules/presence/notify.c index 5b4b9d03fd..00c9c499c0 100644 --- a/modules/presence/notify.c +++ b/modules/presence/notify.c @@ -1995,7 +1995,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs, str* final_body= NULL; str* aux_body = 0; free_body_t* free_fct = 0; - str *ct_body = NULL; + str ct_body = {NULL,0}; LM_DBG("enter: have_body=%d force_null=%d dialog info:\n", (n_body!=0&&n_body->s!=0)?1:0, force_null_body); @@ -2051,7 +2051,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs, notify_body = n_body; } else if (subs->event->build_notify_body) { notify_body = subs->event->build_notify_body( - &subs->pres_uri, &subs->subs_body, ct_body); + &subs->pres_uri, &subs->subs_body, &ct_body); } else { notify_body = get_p_notify_body(subs->pres_uri, subs->event, 0, 0, (subs->contact.s)?&subs->contact:NULL, @@ -2098,7 +2098,7 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs, /* build extra headers */ if( build_str_hdr( subs, notify_body?1:0, &str_hdr, - ct_body, extra_hdrs?extra_hdrs:¬ify_extra_hdrs)< 0 ) + &ct_body, extra_hdrs?extra_hdrs:¬ify_extra_hdrs)< 0 ) { LM_ERR("while building headers\n"); goto error; @@ -2188,8 +2188,8 @@ int send_notify_request(subs_t* subs, subs_t * watcher_subs, pkg_free(str_hdr.s); if (notify_extra_hdrs.s) pkg_free(notify_extra_hdrs.s); - if (ct_body) - pkg_free(ct_body); + if (ct_body.s) + pkg_free(ct_body.s); if((int)(long)n_body!= (int)(long)notify_body) {