From 0ba25358b90cc2e4872fe9729057b2ef9e5f0637 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthm@freeswitch.org>
Date: Thu, 3 Mar 2011 14:21:02 -0600
Subject: [PATCH] FS-3119

---
 src/switch_cpp.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/switch_cpp.cpp b/src/switch_cpp.cpp
index 7d2f281a89..3ffc6a3a9d 100644
--- a/src/switch_cpp.cpp
+++ b/src/switch_cpp.cpp
@@ -501,8 +501,14 @@ SWITCH_DECLARE_CONSTRUCTOR CoreSession::CoreSession()
 
 SWITCH_DECLARE_CONSTRUCTOR CoreSession::CoreSession(char *nuuid, CoreSession *a_leg)
 {
+	switch_channel_t *other_channel = NULL;
+
 	init_vars();
 
+	if (a_leg && a_leg->session) {
+		other_channel = switch_core_session_get_channel(a_leg->session);
+	}
+
 	if (!strchr(nuuid, '/') && (session = switch_core_session_locate(nuuid))) {
 		uuid = strdup(nuuid);
 		channel = switch_core_session_get_channel(session);
@@ -516,7 +522,7 @@ SWITCH_DECLARE_CONSTRUCTOR CoreSession::CoreSession(char *nuuid, CoreSession *a_
 			switch_set_flag(this, S_HUP);
 			uuid = strdup(switch_core_session_get_uuid(session));
 			switch_channel_set_state(switch_core_session_get_channel(session), CS_SOFT_EXECUTE);
-			switch_channel_wait_for_state(switch_core_session_get_channel(session), switch_core_session_get_channel(a_leg->session), CS_SOFT_EXECUTE);
+			switch_channel_wait_for_state(channel, other_channel, CS_SOFT_EXECUTE);
 		}
 	}
 }