[Asterisk-code-review] chan sip.c: Clear scheduled immediate events on unload. (asterisk[13])
Richard Mudgett
asteriskteam at digium.com
Mon Mar 14 18:48:21 CDT 2016
Richard Mudgett has uploaded a new change for review.
https://gerrit.asterisk.org/2391
Change subject: chan_sip.c: Clear scheduled immediate events on unload.
......................................................................
chan_sip.c: Clear scheduled immediate events on unload.
This patch is part of a series to resolve deadlocks in chan_sip.c.
ASTERISK-25023
Change-Id: I3f6540717634f6f2e84d8531a054976f2bbb9d20
---
M channels/chan_sip.c
1 file changed, 31 insertions(+), 22 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/91/2391/1
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index e467b80..e344b0e 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -34799,6 +34799,26 @@
ast_mutex_unlock(&monlock);
}
+ cleanup_all_regs();
+
+ {
+ struct ao2_iterator iter;
+ struct sip_subscription_mwi *iterator;
+
+ iter = ao2_iterator_init(subscription_mwi_list, 0);
+ while ((iterator = ao2_t_iterator_next(&iter, "unload_module iter"))) {
+ ao2_lock(iterator);
+ if (iterator->dnsmgr) {
+ ast_dnsmgr_release(iterator->dnsmgr);
+ iterator->dnsmgr = NULL;
+ ao2_t_ref(iterator, -1, "dnsmgr release");
+ }
+ ao2_unlock(iterator);
+ ao2_t_ref(iterator, -1, "unload_module iter");
+ }
+ ao2_iterator_destroy(&iter);
+ }
+
/* Destroy all the dialogs and free their memory */
i = ao2_iterator_init(dialogs, 0);
while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) {
@@ -34806,6 +34826,13 @@
ao2_t_ref(p, -1, "throw away iterator result");
}
ao2_iterator_destroy(&i);
+
+ /*
+ * Since the monitor thread runs the scheduled events and we
+ * just stopped the monitor thread above, we have to run any
+ * pending scheduled immediate events in this thread.
+ */
+ ast_sched_runq(sched);
/* Free memory for local network address mask */
ast_free_ha(localaddr);
@@ -34826,28 +34853,6 @@
ast_free(default_tls_cfg.cafile);
ast_free(default_tls_cfg.capath);
- cleanup_all_regs();
- ao2_cleanup(registry_list);
-
- {
- struct ao2_iterator iter;
- struct sip_subscription_mwi *iterator;
-
- iter = ao2_iterator_init(subscription_mwi_list, 0);
- while ((iterator = ao2_t_iterator_next(&iter, "unload_module iter"))) {
- ao2_lock(iterator);
- if (iterator->dnsmgr) {
- ast_dnsmgr_release(iterator->dnsmgr);
- iterator->dnsmgr = NULL;
- ao2_t_ref(iterator, -1, "dnsmgr release");
- }
- ao2_unlock(iterator);
- ao2_t_ref(iterator, -1, "unload_module iter");
- }
- ao2_iterator_destroy(&iter);
- }
- ao2_cleanup(subscription_mwi_list);
-
/*
* Wait awhile for the TCP/TLS thread container to become empty.
*
@@ -34862,6 +34867,9 @@
if (!wait_count) {
ast_debug(2, "TCP/TLS thread container did not become empty :(\n");
}
+
+ ao2_cleanup(registry_list);
+ ao2_cleanup(subscription_mwi_list);
ao2_t_global_obj_release(g_bogus_peer, "Release the bogus peer.");
@@ -34882,6 +34890,7 @@
close(sipsock);
io_context_destroy(io);
ast_sched_context_destroy(sched);
+ sched = NULL;
ast_context_destroy_by_name(used_context, "SIP");
ast_unload_realtime("sipregs");
ast_unload_realtime("sippeers");
--
To view, visit https://gerrit.asterisk.org/2391
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I3f6540717634f6f2e84d8531a054976f2bbb9d20
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
More information about the asterisk-code-review
mailing list