Browse code

modules/siptrace: fix regression preventing variables to be used (#2588)

* modules/siptrace: fix regression preventing variables to be used

Commit fa7eb2a switched the 2 parameter version of sip_trace from
using the builtin fixup_spve_spve to the custom fixup method to
using the custom fixup_siptrace. As it is a custom fixup method,
the corresponding free method can not be auto-detected causing the
config parser to require the parameters to be a constant. This
patch adds a free method, allowing variables to be once again passed
as the 2nd parameter of this method (as well as fixing a memory leak
for the 3rd parameter).

* change free for parameter 3

Co-authored-by: Torrey Searle <tsearle@voxbone.com>

tsearle authored on 16/12/2020 20:47:11 • GitHub committed on 16/12/2020 20:47:11
Showing 1 changed files
... ...
@@ -91,6 +91,7 @@ static int w_sip_trace1(struct sip_msg *, char *dest, char *p2);
91 91
 static int w_sip_trace2(struct sip_msg *, char *dest, char *correlation_id);
92 92
 static int w_sip_trace3(struct sip_msg *, char *dest, char *correlation_id, char *trace_type);
93 93
 static int fixup_siptrace(void **param, int param_no);
94
+static int fixup_free_siptrace(void **param, int param_no);
94 95
 static int w_sip_trace_mode(sip_msg_t *msg, char *pmode, char *p2);
95 96
 
96 97
 static int siptrace_parse_uri(str* duri, dest_info_t* dst);
... ...
@@ -203,9 +204,9 @@ static cmd_export_t cmds[] = {
203 204
 		ANY_ROUTE},
204 205
 	{"sip_trace", (cmd_function)w_sip_trace1, 1, fixup_siptrace, 0,
205 206
 		ANY_ROUTE},
206
-	{"sip_trace", (cmd_function)w_sip_trace2, 2, fixup_siptrace, 0,
207
+	{"sip_trace", (cmd_function)w_sip_trace2, 2, fixup_siptrace, fixup_free_siptrace,
207 208
 		ANY_ROUTE},
208
-	{"sip_trace", (cmd_function)w_sip_trace3, 3, fixup_siptrace, 0,
209
+	{"sip_trace", (cmd_function)w_sip_trace3, 3, fixup_siptrace, fixup_free_siptrace,
209 210
 		ANY_ROUTE},
210 211
 	{"hlog", (cmd_function)w_hlog1, 1, fixup_spve_null, 0,
211 212
 		ANY_ROUTE},
... ...
@@ -785,6 +786,21 @@ static int fixup_siptrace(void **param, int param_no)
785 786
 	return 0;
786 787
 }
787 788
 
789
+static int fixup_free_siptrace(void **param, int param_no)
790
+{
791
+	if (param_no == 1 || param_no == 2) {
792
+		/* correlation id */
793
+		return fixup_free_spve_all(param, param_no);
794
+	} if (param_no == 3) {
795
+		/* tracing type; string only */
796
+		if (*param) {
797
+			pkg_free(*param);
798
+		}
799
+	}
800
+
801
+	return 0;
802
+}
803
+
788 804
 
789 805
 /**
790 806
  *