Skip to content

Commit

Permalink
dmq: add missing memory allocation checks, convert to memory log macros
Browse files Browse the repository at this point in the history
  • Loading branch information
pantelisk98 authored and henningw committed Mar 14, 2023
1 parent aa4d015 commit 7e617ab
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 17 deletions.
7 changes: 4 additions & 3 deletions src/modules/dmq/dmq.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ static int make_socket_str_from_uri(struct sip_uri *uri, str *socket)
socket->len = uri->host.len + uri->port.len + 7 /*sctp + : + : \0*/;
socket->s = pkg_malloc(socket->len);
if(socket->s == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
return -1;
}

Expand Down Expand Up @@ -245,14 +245,15 @@ static int mod_init(void)
/* allocate workers array */
dmq_workers = shm_malloc(dmq_num_workers * sizeof(dmq_worker_t));
if(dmq_workers == NULL) {
LM_ERR("error in shm_malloc\n");
SHM_MEM_ERROR;
return -1;
}
memset(dmq_workers, 0, dmq_num_workers * sizeof(dmq_worker_t));

dmq_init_callback_done = shm_malloc(sizeof(int));
if(!dmq_init_callback_done) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
shm_free(dmq_workers);
return -1;
}
*dmq_init_callback_done = 0;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/dmq/dmq_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ int build_uri_str(str *username, struct sip_uri *uri, str *from)
+ TRANSPORT_PARAM_LEN;
from->s = pkg_malloc(from_len);
if(from->s == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
return -1;
}
from->len = 0;
Expand Down Expand Up @@ -231,7 +231,7 @@ int dmq_send_message(dmq_peer_t *peer, str *body, dmq_node_t *node,
str_hdr.len = 34 + content_type->len + (CRLF_LEN * 2);
str_hdr.s = pkg_malloc(str_hdr.len);
if(str_hdr.s == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
return -1;
}
len += sprintf(str_hdr.s, "Max-Forwards: %d" CRLF "Content-Type: %.*s" CRLF,
Expand All @@ -240,7 +240,7 @@ int dmq_send_message(dmq_peer_t *peer, str *body, dmq_node_t *node,

cb_param = shm_malloc(sizeof(*cb_param));
if(cb_param == NULL) {
LM_ERR("no more shm for building callback parameter\n");
SHM_MEM_ERROR;
goto error;
}
memset(cb_param, 0, sizeof(*cb_param));
Expand Down
8 changes: 4 additions & 4 deletions src/modules/dmq/dmqnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ dmq_node_list_t *init_dmq_node_list()
dmq_node_list_t *node_list;
node_list = shm_malloc(sizeof(dmq_node_list_t));
if(node_list == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return NULL;
}
memset(node_list, 0, sizeof(dmq_node_list_t));
Expand Down Expand Up @@ -164,7 +164,7 @@ dmq_node_t *build_dmq_node(str *uri, int shm)
if(shm) {
ret = shm_malloc(sizeof(dmq_node_t));
if(ret == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
goto error;
}
memset(ret, 0, sizeof(dmq_node_t));
Expand All @@ -174,7 +174,7 @@ dmq_node_t *build_dmq_node(str *uri, int shm)
} else {
ret = pkg_malloc(sizeof(dmq_node_t));
if(ret == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
goto error;
}
memset(ret, 0, sizeof(dmq_node_t));
Expand Down Expand Up @@ -288,7 +288,7 @@ dmq_node_t *shm_dup_node(dmq_node_t *node)

newnode = shm_malloc(sizeof(dmq_node_t));
if(newnode == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return NULL;
}
memcpy(newnode, node, sizeof(dmq_node_t));
Expand Down
2 changes: 1 addition & 1 deletion src/modules/dmq/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ int set_reply_body(struct sip_msg *msg, str *body, str *content_type)
buf = pkg_malloc(sizeof(char) * (len));

if(buf == 0) {
LM_ERR("out of pkg memory\n");
PKG_MEM_ERROR;
return -1;
}
memcpy(buf, "Content-Type: ", sizeof("Content-Type: ") - 1);
Expand Down
4 changes: 2 additions & 2 deletions src/modules/dmq/notification_peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,15 +524,15 @@ str *build_notification_body()
str *body;
body = pkg_malloc(sizeof(str));
if(body == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
return NULL;
}
memset(body, 0, sizeof(str));
/* we allocate a chunk of data for the body */
body->len = NBODY_LEN;
body->s = pkg_malloc(body->len);
if(body->s == NULL) {
LM_ERR("no more pkg\n");
PKG_MEM_ERROR;
pkg_free(body);
return NULL;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/dmq/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dmq_peer_list_t *init_peer_list()
dmq_peer_list_t *dmq_peer_list;
dmq_peer_list = shm_malloc(sizeof(dmq_peer_list_t));
if(dmq_peer_list == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return NULL;
}
memset(dmq_peer_list, 0, sizeof(dmq_peer_list_t));
Expand Down Expand Up @@ -67,7 +67,7 @@ dmq_peer_t *add_peer(dmq_peer_list_t *peer_list, dmq_peer_t *peer)
new_peer = shm_malloc(
sizeof(dmq_peer_t) + peer->peer_id.len + peer->description.len);
if(new_peer == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return NULL;
}
*new_peer = *peer;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/dmq/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ job_queue_t *alloc_job_queue()

queue = shm_malloc(sizeof(job_queue_t));
if(queue == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return NULL;
}
memset(queue, 0, sizeof(job_queue_t));
Expand Down Expand Up @@ -257,7 +257,7 @@ int job_queue_push(job_queue_t *queue, dmq_job_t *job)

newjob = shm_malloc(sizeof(dmq_job_t));
if(newjob == NULL) {
LM_ERR("no more shm\n");
SHM_MEM_ERROR;
return -1;
}

Expand Down

0 comments on commit 7e617ab

Please sign in to comment.