Module: kamailio
Branch: master
Commit: 673f25e0961cc49ad1804bb524b8e371adc39ff2
URL:
https://github.com/kamailio/kamailio/commit/673f25e0961cc49ad1804bb524b8e37…
Author: Federico Cabiddu <federico.cabiddu(a)gmail.com>
Committer: GitHub <noreply(a)github.com>
Date: 2020-04-22T14:05:26+02:00
Merge pull request #2295 from kamailio/grumvalski/siptrace_memleak_fix
siptrace: siptrace: fix memory leak in fake replies tracing
---
Modified: src/modules/siptrace/siptrace.c
---
Diff:
https://github.com/kamailio/kamailio/commit/673f25e0961cc49ad1804bb524b8e37…
Patch:
https://github.com/kamailio/kamailio/commit/673f25e0961cc49ad1804bb524b8e37…
---
diff --git a/src/modules/siptrace/siptrace.c b/src/modules/siptrace/siptrace.c
index 3bd1f5a98c..5b4c064bec 100644
--- a/src/modules/siptrace/siptrace.c
+++ b/src/modules/siptrace/siptrace.c
@@ -1383,7 +1383,7 @@ static void trace_onreq_out(struct cell *t, int type, struct
tmcb_params *ps)
}
if(sip_trace_msg_attrs(msg, &sto) < 0) {
- return;
+ return;
}
if(ps->send_buf.len > 0) {
@@ -1569,6 +1569,7 @@ static void trace_onreply_out(struct cell *t, int type, struct
tmcb_params *ps)
siptrace_data_t sto;
siptrace_info_t* info;
int faked = 0;
+ int parsed_f = 0;
struct sip_msg *msg;
struct sip_msg *req;
struct ip_addr to_ip;
@@ -1607,10 +1608,15 @@ static void trace_onreply_out(struct cell *t, int type, struct
tmcb_params *ps)
if(msg == NULL || msg == FAKED_REPLY) {
msg = t->uas.request;
faked = 1;
+ /* check if from header has been already parsed.
+ * If not we have to parse it in pkg memory and free it at the end.
+ */
+ if (msg->from && msg->from->parsed == NULL)
+ parsed_f = 1;
}
if(sip_trace_msg_attrs(msg, &sto) < 0) {
- return;
+ goto end;
}
if(faked == 0) {
@@ -1656,7 +1662,7 @@ static void trace_onreply_out(struct cell *t, int type, struct
tmcb_params *ps)
sto.status.s = int2strbuf(ps->code, statusbuf, INT2STR_MAX_LEN,
&sto.status.len);
if(sto.status.s == 0) {
LM_ERR("failure to get the status string\n");
- return;
+ goto end;
}
memset(&to_ip, 0, sizeof(struct ip_addr));
@@ -1686,10 +1692,16 @@ static void trace_onreply_out(struct cell *t, int type, struct
tmcb_params *ps)
if (info->uriState == STRACE_RAW_URI) {
LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message
won't be traced!\n");
- return;
+ goto end;
}
sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ?
&info->u.dest_info : NULL, NULL);
+
+end:
+ if (faked && parsed_f) {
+ free_from(msg->from->parsed);
+ msg->from->parsed = NULL;
+ }
}
static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps)