Selaa lähdekoodia

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

Pantelis Kolatsis 2 vuotta sitten
vanhempi
commit
d77448b3a6

+ 9 - 7
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 */

+ 2 - 2
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;
 		}
 

+ 1 - 1
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;
 	}