Browse code

Merge pull request #2890 from NGSegovia/msrp_tcp_mem_leak

msrp: fix some tcpconn where memory was never cleaned up

Daniel-Constantin Mierla authored on 27/10/2021 13:18:49 • GitHub committed on 27/10/2021 13:18:49
Showing 1 changed files
... ...
@@ -74,6 +74,7 @@ int msrp_relay(msrp_frame_t *mf)
74 74
 	char *l;
75 75
 	int port;
76 76
 	sr_event_param_t evp = {0};
77
+	int ret;
77 78
 
78 79
 	if(mf->buf.len>=MSRP_MAX_FRAME_SIZE-1)
79 80
 		return -1;
... ...
@@ -169,12 +170,17 @@ done:
169 170
 			wsev.len = p - reqbuf;
170 171
 			wsev.id = con->id;
171 172
 			evp.data = (void *)&wsev;
172
-			return sr_event_exec(SREV_TCP_WS_FRAME_OUT, &evp);
173
+			ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, &evp);
174
+			tcpconn_put(con);
175
+			return ret;
173 176
 		}
174 177
 		else if (tcp_send(dst, 0, reqbuf, p - reqbuf) < 0) {
175 178
 			LM_ERR("forwarding frame failed\n");
179
+			tcpconn_put(con);
176 180
 			return -1;
177 181
 		}
182
+
183
+		tcpconn_put(con);
178 184
 	}
179 185
 	else if (tcp_send(dst, 0, reqbuf, p - reqbuf) < 0) {
180 186
 			LM_ERR("forwarding frame failed\n");
... ...
@@ -195,6 +201,7 @@ int msrp_reply(msrp_frame_t *mf, str *code, str *text, str *xhdrs)
195 201
 	char *p;
196 202
 	char *l;
197 203
 	sr_event_param_t evp = {0};
204
+	int ret;
198 205
 
199 206
 	/* no reply for a reply */
200 207
 	if(mf->fline.msgtypeid==MSRP_REPLY)
... ...
@@ -301,7 +308,9 @@ int msrp_reply(msrp_frame_t *mf, str *code, str *text, str *xhdrs)
301 308
 		wsev.len = p - rplbuf;
302 309
 		wsev.id = con->id;
303 310
 		evp.data = (void *)&wsev;
304
-		return sr_event_exec(SREV_TCP_WS_FRAME_OUT, &evp);
311
+		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, &evp);
312
+		tcpconn_put(con);
313
+		return ret;
305 314
 	}
306 315
 	else
307 316
 	if (tcp_send(&env->srcinfo, 0, rplbuf, p - rplbuf) < 0) {