Skip to content

Commit

Permalink
websocket: convert to memory logging helper, add missing mem error lo…
Browse files Browse the repository at this point in the history
…gging
  • Loading branch information
pantelisk98 authored and henningw committed Apr 29, 2023
1 parent 7ae8207 commit d77448b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
16 changes: 9 additions & 7 deletions src/modules/websocket/ws_conn.c
Expand Up @@ -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,
Expand All @@ -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));
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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 */
Expand Down
4 changes: 2 additions & 2 deletions src/modules/websocket/ws_frame.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/modules/websocket/ws_handshake.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit d77448b

Please sign in to comment.