Module: kamailio
Branch: master
Commit: d77448b3a6a5dc3cf9e9a8ed85aeb7ae743900b6
URL: 
https://github.com/kamailio/kamailio/commit/d77448b3a6a5dc3cf9e9a8ed85aeb7ae743900b6

Author: Pantelis Kolatsis <[email protected]>
Committer: Henning Westerholt <[email protected]>
Date: 2023-04-29T19:16:32Z

websocket: convert to memory logging helper, add missing mem error logging

---

Modified: src/modules/websocket/ws_conn.c
Modified: src/modules/websocket/ws_frame.c
Modified: src/modules/websocket/ws_handshake.c

---

Diff:  
https://github.com/kamailio/kamailio/commit/d77448b3a6a5dc3cf9e9a8ed85aeb7ae743900b6.diff
Patch: 
https://github.com/kamailio/kamailio/commit/d77448b3a6a5dc3cf9e9a8ed85aeb7ae743900b6.patch

---

diff --git a/src/modules/websocket/ws_conn.c b/src/modules/websocket/ws_conn.c
index 1a4f8ffbb3c..0825d366083 100644
--- a/src/modules/websocket/ws_conn.c
+++ b/src/modules/websocket/ws_conn.c
@@ -100,7 +100,7 @@ int wsconn_init(void)
        wsconn_id_hash = (ws_connection_t **)shm_malloc(
                        TCP_ID_HASH_SIZE * sizeof(ws_connection_t *));
        if(wsconn_id_hash == NULL) {
-               LM_ERR("allocating WebSocket hash-table\n");
+               SHM_MEM_ERROR_FMT("for WebSocket hash-table\n");
                goto error;
        }
        memset((void *)wsconn_id_hash, 0,
@@ -109,7 +109,7 @@ int wsconn_init(void)
        wsconn_used_list = (ws_connection_list_t *)shm_malloc(
                        sizeof(ws_connection_list_t));
        if(wsconn_used_list == NULL) {
-               LM_ERR("allocating WebSocket used list\n");
+               SHM_MEM_ERROR_FMT("for WebSocket used list\n");
                goto error;
        }
        memset((void *)wsconn_used_list, 0, sizeof(ws_connection_list_t));
@@ -197,7 +197,7 @@ int wsconn_add(struct receive_info *rcv, unsigned int 
sub_protocol)
        /* Allocate and fill in new WebSocket connection */
        wsc = shm_malloc(sizeof(ws_connection_t) + BUF_SIZE + 1);
        if(wsc == NULL) {
-               LM_ERR("allocating shared memory\n");
+               SHM_MEM_ERROR;
                return -1;
        }
        memset(wsc, 0, sizeof(ws_connection_t) + BUF_SIZE + 1);
@@ -530,9 +530,10 @@ ws_connection_t **wsconn_get_list(void)
        /* allocate a NULL terminated list of wsconn pointers */
        list_size = (list_len + 1) * sizeof(ws_connection_t *);
        list = pkg_malloc(list_size);
-       if(!list)
+       if(!list) {
+               PKG_MEM_ERROR;
                goto end;
-
+       }
        memset(list, 0, list_size);
 
        /* copy */
@@ -618,9 +619,10 @@ ws_connection_id_t *wsconn_get_list_ids(int idx)
        /* allocate a NULL terminated list of wsconn pointers */
        list_size = (list_len + 1) * sizeof(ws_connection_id_t);
        list = pkg_malloc(list_size);
-       if(!list)
+       if(!list) {
+               PKG_MEM_ERROR;
                goto end;
-
+       }
        memset(list, 0, list_size);
 
        /* copy */
diff --git a/src/modules/websocket/ws_frame.c b/src/modules/websocket/ws_frame.c
index c7927b16f43..e4f1a8effd5 100644
--- a/src/modules/websocket/ws_frame.c
+++ b/src/modules/websocket/ws_frame.c
@@ -203,7 +203,7 @@ static int encode_and_send_ws_frame(ws_frame_t *frame, 
conn_close_t conn_close)
        /* Allocate send buffer and build frame */
        frame_length = frame->payload_len + extended_length + 2;
        if((send_buf = pkg_malloc(sizeof(char) * frame_length)) == NULL) {
-               LM_ERR("allocating send buffer from pkg memory\n");
+               PKG_MEM_ERROR_FMT("for send buffer\n");
                return -1;
        }
        memset(send_buf, 0, sizeof(char) * frame_length);
@@ -316,7 +316,7 @@ static int close_connection(ws_connection_t **p_wsc, 
ws_close_type_t type,
        if(wsc->state == WS_S_OPEN) {
                data = pkg_malloc(sizeof(char) * (reason.len + 2));
                if(data == NULL) {
-                       LM_ERR("allocating pkg memory\n");
+                       PKG_MEM_ERROR;
                        return -1;
                }
 
diff --git a/src/modules/websocket/ws_handshake.c 
b/src/modules/websocket/ws_handshake.c
index 878c483f2ab..4566065bd64 100644
--- a/src/modules/websocket/ws_handshake.c
+++ b/src/modules/websocket/ws_handshake.c
@@ -296,7 +296,7 @@ int ws_handle_handshake(struct sip_msg *msg)
        reply_key.s =
                        (char *)pkg_malloc((key.len + str_ws_guid.len) * 
sizeof(char));
        if(reply_key.s == NULL) {
-               LM_ERR("allocating pkg memory\n");
+               PKG_MEM_ERROR;
                ws_send_reply(msg, 500, &str_status_internal_server_error, 
NULL);
                goto end;
        }

_______________________________________________
Kamailio (SER) - Development Mailing List
To unsubscribe send an email to [email protected]

Reply via email to