Browse code

core: Fix connection leak with websockets

- Decrease connection ref count after using connection

Hugh Waite authored on 04/07/2013 09:30:51
Showing 1 changed files
... ...
@@ -134,6 +134,7 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
134 134
 	union sockaddr_union local_addr;
135 135
 	struct tcp_connection *con = NULL;
136 136
 	struct ws_event_info wsev;
137
+	int ret;
137 138
 #endif
138 139
 	
139 140
 	outb.s = buf;
... ...
@@ -162,13 +163,13 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
162 162
 			con = tcpconn_get(dst->id, 0, 0, 0, 0);
163 163
 		else {
164 164
 			LM_CRIT("BUG: msg_send called with null_id & to\n");
165
-			return -1;
165
+			goto error;
166 166
 		}
167 167
 
168 168
 		if (con == NULL)
169 169
 		{
170 170
 			LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
171
-			return -1;
171
+			goto error;
172 172
 		}
173 173
 
174 174
 		memset(&wsev, 0, sizeof(ws_event_info_t));
... ...
@@ -176,7 +177,9 @@ static inline int msg_send(struct dest_info* dst, char* buf, int len)
176 176
 		wsev.buf = outb.s;
177 177
 		wsev.len = outb.len;
178 178
 		wsev.id = con->id;
179
-		return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
179
+		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
180
+		tcpconn_put(con);
181
+		return ret;
180 182
 	}
181 183
 #endif
182 184