[Asterisk-code-review] res pjsip session: Prevent crash during shutdown. (asterisk[15])

Jenkins2 asteriskteam at digium.com
Wed Jan 31 17:09:02 CST 2018


Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/8109 )

Change subject: res_pjsip_session: Prevent crash during shutdown.
......................................................................

res_pjsip_session: Prevent crash during shutdown.

pjproject does not have a function to reverse pjsip_inv_usage_init.
This means we need to ignore any calls to the functions once shutdown is
final.

ASTERISK-27571 #close

Change-Id: Ia550fcba563e2328f03162d79fb185f16b7c9b9d
---
M res/res_pjsip_session.c
1 file changed, 26 insertions(+), 12 deletions(-)

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



diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 53f60cc..f0606d6 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -3426,8 +3426,12 @@
 
 static void session_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e)
 {
-	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	struct ast_sip_session *session;
 	pjsip_event_id_e type;
+
+	if (ast_shutdown_final()) {
+		return;
+	}
 
 	if (e) {
 		print_debug_details(inv, NULL, e);
@@ -3436,6 +3440,7 @@
 		type = PJSIP_EVENT_UNKNOWN;
 	}
 
+	session = inv->mod_data[session_module.id];
 	if (!session) {
 		return;
 	}
@@ -3537,13 +3542,7 @@
 	struct ast_sip_session *session;
 	pjsip_tx_data *tdata;
 
-	/*
-	 * A race condition exists at shutdown where the res_pjsip_session can be
-	 * unloaded but this callback may still get called afterwards. In this case
-	 * the id may end up being -1 which is useless to us. To work around this
-	 * we store the current value and check/use it.
-	 */
-	if (id < 0) {
+	if (ast_shutdown_final()) {
 		return;
 	}
 
@@ -3992,9 +3991,14 @@
 
 static void session_inv_on_rx_offer(pjsip_inv_session *inv, const pjmedia_sdp_session *offer)
 {
-	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	struct ast_sip_session *session;
 	pjmedia_sdp_session *answer;
 
+	if (ast_shutdown_final()) {
+		return;
+	}
+
+	session = inv->mod_data[session_module.id];
 	if (handle_incoming_sdp(session, offer)) {
 		return;
 	}
@@ -4013,9 +4017,14 @@
 
 static void session_inv_on_media_update(pjsip_inv_session *inv, pj_status_t status)
 {
-	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	struct ast_sip_session *session;
 	const pjmedia_sdp_session *local, *remote;
 
+	if (ast_shutdown_final()) {
+		return;
+	}
+
+	session = inv->mod_data[session_module.id];
 	if (!session || !session->channel) {
 		/*
 		 * If we don't have a session or channel then we really
@@ -4038,10 +4047,15 @@
 
 static pjsip_redirect_op session_inv_on_redirected(pjsip_inv_session *inv, const pjsip_uri *target, const pjsip_event *e)
 {
-	struct ast_sip_session *session = inv->mod_data[session_module.id];
+	struct ast_sip_session *session;
 	const pjsip_sip_uri *uri;
 
-	if (!session->channel) {
+	if (ast_shutdown_final()) {
+		return PJSIP_REDIRECT_STOP;
+	}
+
+	session = inv->mod_data[session_module.id];
+	if (!session || !session->channel) {
 		return PJSIP_REDIRECT_STOP;
 	}
 

-- 
To view, visit https://gerrit.asterisk.org/8109
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 15
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia550fcba563e2328f03162d79fb185f16b7c9b9d
Gerrit-Change-Number: 8109
Gerrit-PatchSet: 1
Gerrit-Owner: Corey Farrell <git at cfware.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/20180131/405e46ca/attachment.html>


More information about the asterisk-code-review mailing list