Module: sip-router
Branch: 4.0
Commit: 76319cf9600b71364e3cd6509f61da2f60b2f10f
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=76319cf9600b71364e3cd6509f61da2f60b2f10f

Author: Hugh Waite <[email protected]>
Committer: Hugh Waite <[email protected]>
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
(cherry picked from commit d0f88e19577d9b914922f83049075b7786f3d8df)

---

 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 0adde39..9f9069f 100644
--- a/modules/websocket/ws_conn.c
+++ b/modules/websocket/ws_conn.c
@@ -90,7 +90,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");
@@ -364,7 +364,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 ad26103..e54a830 100644
--- a/modules/websocket/ws_frame.c
+++ b/modules/websocket/ws_frame.c
@@ -219,6 +219,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;
@@ -230,6 +231,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;
                }
        }
@@ -240,6 +242,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;
                }               
        }
@@ -250,6 +253,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;
                }               
        }
@@ -291,15 +295,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);


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to