Browse code

siptrace: siptrace: fix memory leak in fake replies tracing

Federico Cabiddu authored on 22/04/2020 07:34:20
Showing 1 changed files
... ...
@@ -1569,6 +1569,7 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1569 1569
 	siptrace_data_t sto;
1570 1570
 	siptrace_info_t* info;
1571 1571
 	int faked = 0;
1572
+	int parsed_f = 0;
1572 1573
 	struct sip_msg *msg;
1573 1574
 	struct sip_msg *req;
1574 1575
 	struct ip_addr to_ip;
... ...
@@ -1607,6 +1608,11 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1607 1608
 	if(msg == NULL || msg == FAKED_REPLY) {
1608 1609
 		msg = t->uas.request;
1609 1610
 		faked = 1;
1611
+		/* check if from header has been already parsed.
1612
+		 * If not we have to parse it in pkg memory and free it at the end.
1613
+		 */
1614
+		if (msg->from && msg->from->parsed == NULL)
1615
+			parsed_f = 1;
1610 1616
 	}
1611 1617
 
1612 1618
 	if(sip_trace_msg_attrs(msg, &sto) < 0) {
... ...
@@ -1686,10 +1692,16 @@ static void trace_onreply_out(struct cell *t, int type, struct tmcb_params *ps)
1686 1692
 
1687 1693
 	if (info->uriState == STRACE_RAW_URI) {
1688 1694
 		LM_BUG("uriState must be either UNUSED or PARSED here! must be a bug! Message won't be traced!\n");
1689
-		return;
1695
+		goto end;
1690 1696
 	}
1691 1697
 
1692 1698
 	sip_trace_store(&sto, info->uriState == STRACE_PARSED_URI ? &info->u.dest_info : NULL, NULL);
1699
+
1700
+end:
1701
+	if (faked && parsed_f) {
1702
+		free_from(msg->from->parsed);
1703
+    msg->from->parsed = NULL;
1704
+	}
1693 1705
 }
1694 1706
 
1695 1707
 static void trace_tm_neg_ack_in(struct cell *t, int type, struct tmcb_params *ps)