[Pkg-voip-commits] [asterisk] 05/10: Add AST-2017-011.patch

tzafrir at debian.org tzafrir at debian.org
Wed Dec 13 20:23:02 UTC 2017


This is an automated email from the git hooks/post-receive script.

tzafrir pushed a commit to branch stretch
in repository asterisk.

commit 9abe68d9a0c955b31e5615da3cdb74693c66eb48
Author: Tzafrir Cohen <tzafrir at debian.org>
Date:   Wed Dec 13 18:26:59 2017 +0200

    Add AST-2017-011.patch
---
 debian/patches/AST-2017-011.patch | 145 ++++++++++++++++++++++++++++++++++++++
 debian/patches/series             |   1 +
 2 files changed, 146 insertions(+)

diff --git a/debian/patches/AST-2017-011.patch b/debian/patches/AST-2017-011.patch
new file mode 100644
index 0000000..a894b0d
--- /dev/null
+++ b/debian/patches/AST-2017-011.patch
@@ -0,0 +1,145 @@
+From 4b3e03ae871ab5e5ac9d59c685c033623f3ec0b3 Mon Sep 17 00:00:00 2001
+From: Kevin Harwell <kharwell at digium.com>
+Date: Thu, 19 Oct 2017 13:35:16 -0500
+Subject: [PATCH] AST-2017-011 - res_pjsip_session: session leak when a call is
+ rejected
+
+A previous commit made it so when an invite session transitioned into a
+disconnected state destruction of the Asterisk pjsip session object was
+postponed until either a transport error occurred or the event timer
+expired. However, if a call was rejected (for instance a 488) before the
+session was fully established the event timer may not have been initiated,
+or it was canceled without triggering either of the session finalizing states
+mentioned above.
+
+Really the only time destruction of the session should be delayed is when a
+BYE is being transacted. This is because it's possible in some cases for the
+session to be disconnected, but the BYE is still transacting.
+
+This patch makes it so the session object always gets released (no more
+memory leak) when the pjsip session is in a disconnected state. Except when
+the method is a BYE. Then it waits until a transport error occurs or an event
+timeout.
+
+ASTERISK-27345 #close
+
+Reported by: Corey Farrell
+
+Change-Id: I1e724737b758c20ac76d19d3611e3d2876ae10ed
+---
+ res/res_pjsip_session.c | 80 ++++++++++++++++++++++++++-----------------------
+ 1 file changed, 42 insertions(+), 38 deletions(-)
+
+diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
+index c53d52d715..f2ee3478b7 100644
+--- a/res/res_pjsip_session.c
++++ b/res/res_pjsip_session.c
+@@ -2654,6 +2654,36 @@ static void session_inv_on_new_session(pjsip_inv_session *inv, pjsip_event *e)
+ 	/* XXX STUB */
+ }
+ 
++static int session_end_if_disconnected(int id, pjsip_inv_session *inv)
++{
++	struct ast_sip_session *session;
++
++	if (inv->state != PJSIP_INV_STATE_DISCONNECTED) {
++		return 0;
++	}
++
++	/*
++	 * We are locking because ast_sip_dialog_get_session() needs
++	 * the dialog locked to get the session by other threads.
++	 */
++	pjsip_dlg_inc_lock(inv->dlg);
++	session = inv->mod_data[id];
++	inv->mod_data[id] = NULL;
++	pjsip_dlg_dec_lock(inv->dlg);
++
++	/*
++	 * Pass the session ref held by session->inv_session to
++	 * session_end_completion().
++	 */
++	if (session
++		&& ast_sip_push_task(session->serializer, session_end_completion, session)) {
++		/* Do it anyway even though this is not the right thread. */
++		session_end_completion(session);
++	}
++
++	return 1;
++}
++
+ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_transaction *tsx, pjsip_event *e)
+ {
+ 	ast_sip_session_response_cb cb;
+@@ -2678,6 +2708,17 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans
+ 		/* The session has ended.  Ignore the transaction change. */
+ 		return;
+ 	}
++
++	/*
++	 * If the session is disconnected really nothing else to do unless currently transacting
++	 * a BYE. If a BYE then hold off destruction until the transaction timeout occurs. This
++	 * has to be done for BYEs because sometimes the dialog can be in a disconnected
++	 * state but the BYE request transaction has not yet completed.
++	 */
++	if (tsx->method.id != PJSIP_BYE_METHOD && session_end_if_disconnected(id, inv)) {
++		return;
++	}
++
+ 	switch (e->body.tsx_state.type) {
+ 	case PJSIP_EVENT_TX_MSG:
+ 		/* When we create an outgoing request, we do not have access to the transaction that
+@@ -2800,49 +2841,12 @@ static void session_inv_on_tsx_state_changed(pjsip_inv_session *inv, pjsip_trans
+ 		}
+ 		break;
+ 	case PJSIP_EVENT_TRANSPORT_ERROR:
+-		if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
+-			/*
+-			 * Clear the module data now to block session_inv_on_state_changed()
+-			 * from calling session_end() if it hasn't already done so.
+-			 */
+-			inv->mod_data[id] = NULL;
+-
+-			/*
+-			 * Pass the session ref held by session->inv_session to
+-			 * session_end_completion().
+-			 */
+-			if (session
+-				&& ast_sip_push_task(session->serializer, session_end_completion, session)) {
+-				/* Do it anyway even though this is not the right thread. */
+-				session_end_completion(session);
+-			}
+-			return;
+-		}
+-		break;
+ 	case PJSIP_EVENT_TIMER:
+ 		/*
+ 		 * The timer event is run by the pjsip monitor thread and not
+ 		 * by the session serializer.
+ 		 */
+-		if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
+-			/*
+-			 * We are locking because ast_sip_dialog_get_session() needs
+-			 * the dialog locked to get the session by other threads.
+-			 */
+-			pjsip_dlg_inc_lock(inv->dlg);
+-			session = inv->mod_data[id];
+-			inv->mod_data[id] = NULL;
+-			pjsip_dlg_dec_lock(inv->dlg);
+-
+-			/*
+-			 * Pass the session ref held by session->inv_session to
+-			 * session_end_completion().
+-			 */
+-			if (session
+-				&& ast_sip_push_task(session->serializer, session_end_completion, session)) {
+-				/* Do it anyway even though this is not the right thread. */
+-				session_end_completion(session);
+-			}
++		if (session_end_if_disconnected(id, inv)) {
+ 			return;
+ 		}
+ 		break;
+-- 
+2.11.0
+
diff --git a/debian/patches/series b/debian/patches/series
index b378761..2dea6f8 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -52,4 +52,5 @@ AST-2017-006-13.diff
 AST-2017-008-13.13.diff
 # AST-2017-009: irrelevant: a patch to pjproject
 AST-2017-010.patch
+AST-2017-011.patch
 AST-2017-012.patch

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/asterisk.git



More information about the Pkg-voip-commits mailing list