Module: sip-router Branch: master Commit: d0f88e19577d9b914922f83049075b7786f3d8df URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=d0f88e19...
Author: Hugh Waite hugh.waite@crocodile-rcs.com Committer: Hugh Waite hugh.waite@crocodile-rcs.com Date: Wed Jul 3 10:46:44 2013 +0100
modules/websocket: Fix pkg memory leaks
- Fix pkg memory leaks in error cases - Fix incorrect memory allocation size for ws connections - Fix typo in websocket stats
---
modules/websocket/ws_conn.c | 4 ++-- modules/websocket/ws_frame.c | 18 +++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/modules/websocket/ws_conn.c b/modules/websocket/ws_conn.c index 92e2559..aeda6b2 100644 --- a/modules/websocket/ws_conn.c +++ b/modules/websocket/ws_conn.c @@ -94,7 +94,7 @@ int wsconn_init(void)
wsconn_id_hash = (ws_connection_t **) shm_malloc(TCP_ID_HASH_SIZE * - sizeof(ws_connection_t)); + sizeof(ws_connection_t*)); if (wsconn_id_hash == NULL) { LM_ERR("allocating WebSocket hash-table\n"); @@ -395,7 +395,7 @@ static int add_node(struct mi_root *tree, ws_connection_t *wsc)
dst_proto = (con->rcv.proto == PROTO_WS) ? "ws" : "wss"; memset(dst_ip, 0, IP6_MAX_STR_SIZE + 1); - ip_addr2sbuf(&con->rcv.dst_ip, src_ip, IP6_MAX_STR_SIZE); + ip_addr2sbuf(&con->rcv.dst_ip, dst_ip, IP6_MAX_STR_SIZE);
pong = wsc->awaiting_pong ? "awaiting Pong, " : "";
diff --git a/modules/websocket/ws_frame.c b/modules/websocket/ws_frame.c index 7b76bac..263f4d2 100644 --- a/modules/websocket/ws_frame.c +++ b/modules/websocket/ws_frame.c @@ -228,6 +228,7 @@ static int encode_and_send_ws_frame(ws_frame_t *frame, conn_close_t conn_close) if ((con = tcpconn_get(frame->wsc->id, 0, 0, 0, 0)) == NULL) { LM_WARN("TCP/TLS connection get failed\n"); + pkg_free(send_buf); if (wsconn_rm(frame->wsc, WSCONN_EVENTROUTE_YES) < 0) LM_ERR("removing WebSocket connection\n"); return -1; @@ -239,6 +240,7 @@ static int encode_and_send_ws_frame(ws_frame_t *frame, conn_close_t conn_close) if (wsconn_rm(frame->wsc, WSCONN_EVENTROUTE_YES) < 0) { LM_ERR("removing WebSocket connection\n"); + pkg_free(send_buf); return -1; } } @@ -249,6 +251,7 @@ static int encode_and_send_ws_frame(ws_frame_t *frame, conn_close_t conn_close) { STATS_TX_DROPS; LM_WARN("TCP disabled\n"); + pkg_free(send_buf); return -1; } } @@ -259,6 +262,7 @@ static int encode_and_send_ws_frame(ws_frame_t *frame, conn_close_t conn_close) { STATS_TX_DROPS; LM_WARN("TLS disabled\n"); + pkg_free(send_buf); return -1; } } @@ -313,15 +317,15 @@ static int close_connection(ws_connection_t *wsc, ws_close_type_t type, char *data; ws_frame_t frame;
- data = pkg_malloc(sizeof(char) * (reason.len + 2)); - if (data == NULL) - { - LM_ERR("allocating pkg memory\n"); - return -1; - } - if (wsc->state == WS_S_OPEN) { + data = pkg_malloc(sizeof(char) * (reason.len + 2)); + if (data == NULL) + { + LM_ERR("allocating pkg memory\n"); + return -1; + } + data[0] = (status & 0xff00) >> 8; data[1] = (status & 0x00ff) >> 0; memcpy(&data[2], reason.s, reason.len);