Skip to content

Commit

Permalink
Proper reset of the sip_msg struct after each run of timer route.
Browse files Browse the repository at this point in the history
Some cleanup of the free_sip_msg() function. This function is suppose to only free the attached content of a SIP msg, but without doing any kind of reset of the subfields.
Closes #1878

(cherry picked from commit b3dc0f7)
  • Loading branch information
bogdan-iancu committed Nov 13, 2019
1 parent beb72cb commit d877afe
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
38 changes: 22 additions & 16 deletions parser/msg_parser.c
Expand Up @@ -807,26 +807,32 @@ void free_reply_lump( struct lump_rpl *lump)
}


/*only the content*/
/* Free only the content, not the msg structure itself
* NOTE: the function doesn't do any cleanup/reset of the subfields */
void free_sip_msg(struct sip_msg* msg)
{
if (msg->msg_cb) { msg_callback_process(msg, MSG_DESTROY, NULL); }
if (msg->new_uri.s) { pkg_free(msg->new_uri.s); msg->new_uri.len=0; }
if (msg->set_global_address.s) {
if (msg->msg_cb)
msg_callback_process(msg, MSG_DESTROY, NULL);
if (msg->new_uri.s)
pkg_free(msg->new_uri.s);
if (msg->set_global_address.s)
pkg_free(msg->set_global_address.s);
msg->set_global_address.s = NULL;
}
if (msg->set_global_port.s) {
if (msg->set_global_port.s)
pkg_free(msg->set_global_port.s);
msg->set_global_port.s = NULL;
}
if (msg->dst_uri.s) { pkg_free(msg->dst_uri.s); msg->dst_uri.len=0; }
if (msg->path_vec.s) { pkg_free(msg->path_vec.s); msg->path_vec.len=0; }
if (msg->headers) free_hdr_field_lst(msg->headers);
if (msg->add_rm) free_lump_list(msg->add_rm);
if (msg->body_lumps) free_lump_list(msg->body_lumps);
if (msg->reply_lump) free_reply_lump(msg->reply_lump);
if (msg->body ) { free_sip_body(msg->body);msg->body = 0;}
if (msg->dst_uri.s)
pkg_free(msg->dst_uri.s);
if (msg->path_vec.s)
pkg_free(msg->path_vec.s);
if (msg->headers)
free_hdr_field_lst(msg->headers);
if (msg->add_rm)
free_lump_list(msg->add_rm);
if (msg->body_lumps)
free_lump_list(msg->body_lumps);
if (msg->reply_lump)
free_reply_lump(msg->reply_lump);
if (msg->body )
free_sip_body(msg->body);
/* don't free anymore -- now a pointer to a static buffer */
}

Expand Down
25 changes: 13 additions & 12 deletions timer.c
Expand Up @@ -234,6 +234,11 @@ void route_timer_f(unsigned int ticks, void* param)
struct action* a = (struct action*)param;
static struct sip_msg* req= NULL;

if(a == NULL) {
LM_ERR("NULL action\n");
return;
}

if(req == NULL)
{
req = (struct sip_msg*)pkg_malloc(sizeof(struct sip_msg));
Expand All @@ -242,20 +247,16 @@ void route_timer_f(unsigned int ticks, void* param)
LM_ERR("No more memory\n");
return;
}
memset(req, 0, sizeof(struct sip_msg));
req->first_line.type = SIP_REQUEST;
req->first_line.u.request.method.s= "DUMMY";
req->first_line.u.request.method.len= 5;
req->first_line.u.request.uri.s= "sip:user@domain.com";
req->first_line.u.request.uri.len= 19;
req->rcv.src_ip.af = AF_INET;
req->rcv.dst_ip.af = AF_INET;
}

if(a == NULL) {
LM_ERR("NULL action\n");
return;
}
memset(req, 0, sizeof(struct sip_msg));
req->first_line.type = SIP_REQUEST;
req->first_line.u.request.method.s= "DUMMY";
req->first_line.u.request.method.len= 5;
req->first_line.u.request.uri.s= "sip:user@domain.com";
req->first_line.u.request.uri.len= 19;
req->rcv.src_ip.af = AF_INET;
req->rcv.dst_ip.af = AF_INET;

run_top_route(a, req);

Expand Down

0 comments on commit d877afe

Please sign in to comment.