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 163
 			con = tcpconn_get(dst->id, 0, 0, 0, 0);
163 164
 		else {
164 165
 			LM_CRIT("BUG: msg_send called with null_id & to\n");
165
-			return -1;
166
+			goto error;
166 167
 		}
167 168
 
168 169
 		if (con == NULL)
169 170
 		{
170 171
 			LM_WARN("TCP/TLS connection for WebSocket could not be found\n");
171
-			return -1;
172
+			goto error;
172 173
 		}
173 174
 
174 175
 		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 177
 		wsev.buf = outb.s;
177 178
 		wsev.len = outb.len;
178 179
 		wsev.id = con->id;
179
-		return sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
180
+		ret = sr_event_exec(SREV_TCP_WS_FRAME_OUT, (void *) &wsev);
181
+		tcpconn_put(con);
182
+		return ret;
180 183
 	}
181 184
 #endif
182 185