Module: kamailio Branch: master Commit: 51d2f707562f70749dd02727a34dc5e4fa20712e URL: https://github.com/kamailio/kamailio/commit/51d2f707562f70749dd02727a34dc5e4...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2022-10-25T10:06:06+02:00
nats: safety check for nats_workers and nats_pub_workers on mod destroy
---
Modified: src/modules/nats/nats_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/51d2f707562f70749dd02727a34dc5e4... Patch: https://github.com/kamailio/kamailio/commit/51d2f707562f70749dd02727a34dc5e4...
---
diff --git a/src/modules/nats/nats_mod.c b/src/modules/nats/nats_mod.c index b89bab5bd1..6d26b621ec 100644 --- a/src/modules/nats/nats_mod.c +++ b/src/modules/nats/nats_mod.c @@ -549,47 +549,51 @@ int nats_destroy_workers() int i; nats_consumer_worker_t *worker; nats_pub_worker_t *pub_worker; - for(i = 0; i < _nats_proc_count; i++) { - worker = &nats_workers[i]; - if(worker != NULL) { - if(worker->subscription != NULL) { - natsSubscription_Unsubscribe(worker->subscription); - natsSubscription_Destroy(worker->subscription); - } - if(worker->uvLoop != NULL) { - uv_loop_close(worker->uvLoop); - } - if(worker->subject != NULL) { - shm_free(worker->subject); - } - if(worker->queue_group != NULL) { - shm_free(worker->queue_group); - } - if(worker->nc != NULL) { - if(nats_cleanup_connection(worker->nc) < 0) { - LM_ERR("could not cleanup worker connection\n"); + if(nats_workers != NULL) { + for(i = 0; i < _nats_proc_count; i++) { + worker = &nats_workers[i]; + if(worker != NULL) { + if(worker->subscription != NULL) { + natsSubscription_Unsubscribe(worker->subscription); + natsSubscription_Destroy(worker->subscription); } - } - if(worker->on_message != NULL) { - if (worker->on_message->_evname) { - free(worker->on_message->_evname); + if(worker->uvLoop != NULL) { + uv_loop_close(worker->uvLoop); + } + if(worker->subject != NULL) { + shm_free(worker->subject); } - shm_free(worker->on_message); + if(worker->queue_group != NULL) { + shm_free(worker->queue_group); + } + if(worker->nc != NULL) { + if(nats_cleanup_connection(worker->nc) < 0) { + LM_ERR("could not cleanup worker connection\n"); + } + } + if(worker->on_message != NULL) { + if (worker->on_message->_evname) { + free(worker->on_message->_evname); + } + shm_free(worker->on_message); + } + shm_free(worker); } - shm_free(worker); } }
- for(i = 0; i < nats_pub_workers_num; i++) { - pub_worker = &nats_pub_workers[i]; - if(pub_worker != NULL) { - if(pub_worker->nc != NULL) { - if(nats_cleanup_connection(pub_worker->nc) < 0) { - LM_ERR("could not cleanup worker connection\n"); + if(nats_pub_workers != NULL) { + for(i = 0; i < nats_pub_workers_num; i++) { + pub_worker = &nats_pub_workers[i]; + if(pub_worker != NULL) { + if(pub_worker->nc != NULL) { + if(nats_cleanup_connection(pub_worker->nc) < 0) { + LM_ERR("could not cleanup worker connection\n"); + } } + uv_poll_stop(&pub_worker->poll); + shm_free(pub_worker); } - uv_poll_stop(&pub_worker->poll); - shm_free(pub_worker); } } return 0; @@ -600,9 +604,6 @@ int nats_destroy_workers() */ static void mod_destroy(void) { - if(nats_workers==NULL) { - return; - } if(nats_destroy_workers() < 0) { LM_ERR("could not cleanup workers\n"); }