res_pjsip_diversion: Use static pj_str_t for Diversion header names

PJSIP assumes that these header names are not allocated, and does not
clone the name strings when reusing headers.

Block unload of res_pjsip_diversion until shutdown to ensure static
memory stays valid.

ASTERISK-28312 #close

Change-Id: Ibd6ea55ec4a604bbd43ac07f8d0b54da2c39b8b9
This commit is contained in:
Sean Bright
2019-02-28 11:01:15 -05:00
parent c4a172efba
commit 5821090661

View File

@@ -326,8 +326,7 @@ static void add_diversion_header(pjsip_tx_data *tdata, struct ast_party_redirect
hdr = pjsip_from_hdr_create(tdata->pool);
hdr->type = PJSIP_H_OTHER;
pj_strdup(tdata->pool, &hdr->name, &diversion_name);
hdr->sname = hdr->name;
hdr->sname = hdr->name = diversion_name;
name_addr = pjsip_uri_clone(tdata->pool, base);
uri = pjsip_uri_get_uri(name_addr->uri);
@@ -414,6 +413,9 @@ static int load_module(void)
{
CHECK_PJSIP_SESSION_MODULE_LOADED();
/* Because we are passing static memory to pjsip, we need to make sure it
* stays valid while we potentially have active sessions */
ast_module_shutdown_ref(ast_module_info->self);
ast_sip_session_register_supplement(&diversion_supplement);
return AST_MODULE_LOAD_SUCCESS;
}