Explorar el Código

dmq: Various sanity checks and initializations

Alex Hermann hace 11 años
padre
commit
3e34dbf68b
Se han modificado 3 ficheros con 17 adiciones y 3 borrados
  1. 1 1
      modules/dmq/dmq.c
  2. 7 2
      modules/dmq/dmq_funcs.c
  3. 9 0
      modules/dmq/dmqnode.c

+ 1 - 1
modules/dmq/dmq.c

@@ -300,7 +300,7 @@ static int child_init(int rank)
  */
 static void destroy(void) {
 	/* TODO unregister dmq node, free resources */
-	if(dmq_notification_address.s) {
+	if(dmq_notification_address.s && notification_node && self_node) {
 		LM_DBG("unregistering node %.*s\n", STR_FMT(&self_node->orig_uri));
 		self_node->status = DMQ_NODE_DISABLED;
 		request_nodelist(notification_node, 1);

+ 7 - 2
modules/dmq/dmq_funcs.c

@@ -76,7 +76,6 @@ int build_uri_str(str* username, struct sip_uri* uri, str* from)
 	/* sip:user@host:port */
 	int from_len;
 	
-	from_len = username->len + uri->host.len + uri->port.len + 10;
 	if(!uri->host.s || !uri->host.len) {
 		LM_ERR("no host in uri\n");
 		return -1;
@@ -85,6 +84,8 @@ int build_uri_str(str* username, struct sip_uri* uri, str* from)
 		LM_ERR("no username given\n");
 		return -1;
 	}
+
+	from_len = username->len + uri->host.len + uri->port.len + 10;
 	from->s = pkg_malloc(from_len);
 	if(from->s==NULL) {
 		LM_ERR("no more pkg\n");
@@ -166,7 +167,7 @@ int dmq_send_message(dmq_peer_t* peer, str* body, dmq_node_t* node,
 {
 	uac_req_t uac_r;
 	str str_hdr = {0, 0};
-	str from, to;
+	str from = {0, 0}, to = {0, 0};
 	dmq_cback_param_t* cb_param = NULL;
 	int result = 0;
 	int len = 0;
@@ -354,6 +355,10 @@ void ping_servers(unsigned int ticks, void *param) {
 	int ret;
 	LM_DBG("ping_servers\n");
 	body = build_notification_body();
+	if (!body) {
+		LM_ERR("could not build notification body\n");
+		return;
+	}
 	ret = bcast_dmq_message(dmq_notification_peer, body, notification_node,
 			&notification_callback, 1, &notification_content_type);
 	pkg_free(body->s);

+ 9 - 0
modules/dmq/dmqnode.c

@@ -259,6 +259,15 @@ dmq_node_t* find_dmq_node(dmq_node_list_t* list, dmq_node_t* node)
 dmq_node_t* shm_dup_node(dmq_node_t* node)
 {
 	dmq_node_t* newnode;
+	if (!node) {
+		LM_ERR("node is null\n");
+		return NULL;
+	}
+	if (!node->orig_uri.s) {
+		LM_ERR("nod->orig_uri.s is null\n");
+		return NULL;
+	}
+
 	newnode = shm_malloc(sizeof(dmq_node_t));
 	if(newnode==NULL) {
 		LM_ERR("no more shm\n");