Module: kamailio Branch: master Commit: 6fb38cb33095c11a1c90d7b88140ac159b9fd5ca URL: https://github.com/kamailio/kamailio/commit/6fb38cb33095c11a1c90d7b88140ac15...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2025-02-11T10:25:34+01:00
tsilo: clean allocated memory on error for append by contact
---
Modified: src/modules/tsilo/tsilo.c
---
Diff: https://github.com/kamailio/kamailio/commit/6fb38cb33095c11a1c90d7b88140ac15... Patch: https://github.com/kamailio/kamailio/commit/6fb38cb33095c11a1c90d7b88140ac15...
---
diff --git a/src/modules/tsilo/tsilo.c b/src/modules/tsilo/tsilo.c index 5119b3f5a21..6af49d59dd3 100644 --- a/src/modules/tsilo/tsilo.c +++ b/src/modules/tsilo/tsilo.c @@ -459,19 +459,19 @@ static int w_ts_append_by_contact2(
if(ts_check_uri(&ruri) < 0) { LM_ERR("failed to parse R-URI.\n"); - return -1; + goto error; }
/* parse Contact header */ if((!_msg->contact && parse_headers(_msg, HDR_CONTACT_F, 0) != 0) || !_msg->contact) { LM_WARN("missing contact header or the value is empty/malformed.\n"); - return -1; + goto error; } if(_msg->contact) { if(parse_contact(_msg->contact) < 0) { LM_WARN("failed to parse Contact header.\n"); - return -1; + goto error; } if(parse_uri(((struct contact_body *)_msg->contact->parsed) ->contacts->uri.s, @@ -481,7 +481,7 @@ static int w_ts_append_by_contact2( != 0) { if(ts_check_uri(&_msg->contact->body) < 0) { /* one more attempt */ LM_WARN("failed to parse Contact header.\n"); - return -1; + goto error; } }
@@ -490,7 +490,7 @@ static int w_ts_append_by_contact2( tmp_contact.s = (char *)pkg_malloc(tmp_contact.len + 1); if(tmp_contact.s == NULL) { PKG_MEM_ERROR; - return -1; + goto error; } memcpy(tmp_contact.s, ((struct contact_body *)_msg->contact->parsed)->contacts->uri.s, @@ -502,7 +502,7 @@ static int w_ts_append_by_contact2( < 0) { /* one more attempt */ LM_ERR("problems when calling ts_append_contact(), cannot copy " "Contact parameter.\n"); - return -1; + goto error; } } } @@ -516,6 +516,18 @@ static int w_ts_append_by_contact2( pkg_free(tmp_contact.s);
return rc; + +error: + if(ruri.s != NULL) { + pkg_free(ruri.s); + } + if(contact.s != NULL) { + pkg_free(contact.s); + } + if(tmp_contact.s != NULL) { + pkg_free(tmp_contact.s); + } + return -1; }
/** @@ -538,11 +550,11 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str *_table, str *_ruri) /* parse Contact header */ if((!_msg->contact && parse_headers(_msg, HDR_CONTACT_F, 0) != 0) || !_msg->contact) - return -1; + goto error;
if(_msg->contact) { if(parse_contact(_msg->contact) < 0) - return -1; + goto error; if(parse_uri(((struct contact_body *)_msg->contact->parsed) ->contacts->uri.s, ((struct contact_body *)_msg->contact->parsed) @@ -550,7 +562,7 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str *_table, str *_ruri) &curi) != 0) { if(ts_check_uri(&_msg->contact->body) < 0) /* one more attempt */ - return -1; + goto error; }
tmp_contact.len = ((struct contact_body *)_msg->contact->parsed) @@ -558,7 +570,7 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str *_table, str *_ruri) tmp_contact.s = (char *)pkg_malloc(tmp_contact.len + 1); if(tmp_contact.s == NULL) { PKG_MEM_ERROR; - return -1; + goto error; } memcpy(tmp_contact.s, ((struct contact_body *)_msg->contact->parsed)->contacts->uri.s, @@ -568,7 +580,7 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str *_table, str *_ruri) if(pkg_str_dup(&contact, &tmp_contact) < 0) { if(pkg_str_dup(&contact, &_msg->contact->body) < 0) /* one more attempt */ - return -1; + goto error; } }
@@ -580,6 +592,18 @@ static int ki_ts_append_by_contact(sip_msg_t *_msg, str *_table, str *_ruri) pkg_free(tmp_contact.s);
return rc; + +error: + if(ruri.s != NULL) { + pkg_free(ruri.s); + } + if(contact.s != NULL) { + pkg_free(contact.s); + } + if(tmp_contact.s != NULL) { + pkg_free(tmp_contact.s); + } + return -1; }
/**