Skip to content

Commit

Permalink
Pre-allocate the str holder for the CT body for build_notify_body_t
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-iancu committed Dec 3, 2019
1 parent 2caa189 commit 3ebeabf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions modules/presence/event_list.h
Expand Up @@ -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,
Expand Down
10 changes: 5 additions & 5 deletions modules/presence/notify.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:&notify_extra_hdrs)< 0 )
&ct_body, extra_hdrs?extra_hdrs:&notify_extra_hdrs)< 0 )
{
LM_ERR("while building headers\n");
goto error;
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 3ebeabf

Please sign in to comment.