[Asterisk-code-review] res pjsip: Resolve transport management leak at shutdown. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Fri Aug 17 05:38:48 CDT 2018


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/9882 )

Change subject: res_pjsip: Resolve transport management leak at shutdown.
......................................................................

res_pjsip: Resolve transport management leak at shutdown.

Cleanup idle check scheduled events at shutdown.

Change-Id: I61bfbb56bac69fe840c3242927d31ff3593be461
---
M res/res_pjsip/pjsip_transport_management.c
1 file changed, 27 insertions(+), 5 deletions(-)

Approvals:
  George Joseph: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Joshua Colp: Approved for Submit



diff --git a/res/res_pjsip/pjsip_transport_management.c b/res/res_pjsip/pjsip_transport_management.c
index d9866f1..e7483e6 100644
--- a/res/res_pjsip/pjsip_transport_management.c
+++ b/res/res_pjsip/pjsip_transport_management.c
@@ -119,10 +119,8 @@
 
 AST_THREADSTORAGE(desc_storage);
 
-static int idle_sched_cb(const void *data)
+static int idle_sched_init_pj_thread(void)
 {
-	struct monitored_transport *monitored = (struct monitored_transport *) data;
-
 	if (!pj_thread_is_registered()) {
 		pj_thread_t *thread;
 		pj_thread_desc *desc;
@@ -130,8 +128,7 @@
 		desc = ast_threadstorage_get(&desc_storage, sizeof(pj_thread_desc));
 		if (!desc) {
 			ast_log(LOG_ERROR, "Could not get thread desc from thread-local storage.\n");
-			ao2_ref(monitored, -1);
-			return 0;
+			return -1;
 		}
 
 		pj_bzero(*desc, sizeof(*desc));
@@ -139,6 +136,18 @@
 		pj_thread_register("Transport Monitor", *desc, &thread);
 	}
 
+	return 0;
+}
+
+static int idle_sched_cb(const void *data)
+{
+	struct monitored_transport *monitored = (struct monitored_transport *) data;
+
+	if (idle_sched_init_pj_thread()) {
+		ao2_ref(monitored, -1);
+		return 0;
+	}
+
 	if (!monitored->sip_received) {
 		ast_log(LOG_NOTICE, "Shutting down transport '%s' since no request was received in %d seconds\n",
 			monitored->transport->info, IDLE_TIMEOUT / 1000);
@@ -149,6 +158,18 @@
 	return 0;
 }
 
+static int idle_sched_cleanup(const void *data)
+{
+	struct monitored_transport *monitored = (struct monitored_transport *) data;
+
+	if (!idle_sched_init_pj_thread()) {
+		pjsip_transport_shutdown(monitored->transport);
+	}
+	ao2_ref(monitored, -1);
+
+	return 0;
+}
+
 /*! \brief Destructor for keepalive transport */
 static void monitored_transport_destroy(void *obj)
 {
@@ -384,6 +405,7 @@
 
 	internal_sip_unregister_service(&idle_monitor_module);
 
+	ast_sched_clean_by_callback(sched, idle_sched_cb, idle_sched_cleanup);
 	ast_sched_context_destroy(sched);
 	sched = NULL;
 

-- 
To view, visit https://gerrit.asterisk.org/9882
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: merged
Gerrit-Change-Id: I61bfbb56bac69fe840c3242927d31ff3593be461
Gerrit-Change-Number: 9882
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180817/c19f9cc8/attachment.html>


More information about the asterisk-code-review mailing list