From 61f71489416fe58a3bb20a13b4fd86ad3f523fb4 Mon Sep 17 00:00:00 2001
From: Anthony Minessale <anthony.minessale@gmail.com>
Date: Wed, 25 Oct 2006 14:01:03 +0000
Subject: [PATCH] tidy up

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@3196 d0543943-73ff-0310-b7d9-9358b9ac24b2
---
 src/mod/endpoints/mod_sofia/Makefile    |  2 +-
 src/mod/endpoints/mod_sofia/mod_sofia.c | 17 ++++++++++++-----
 2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/Makefile b/src/mod/endpoints/mod_sofia/Makefile
index fc75f03687..da3a8b0ec5 100644
--- a/src/mod/endpoints/mod_sofia/Makefile
+++ b/src/mod/endpoints/mod_sofia/Makefile
@@ -1,6 +1,6 @@
 OS_ARCH         := $(subst /,_,$(shell uname -s | sed /\ /s//_/))
 VERSION = sofia-sip-1.12
-TARBALL = sofia-sip-1.12.3.5.tar.gz
+TARBALL = sofia-sip-1.12.3.6.tar.gz
 CFLAGS += -I. -I$(PREFIX)/include/$(VERSION)
 LDFLAGS += -lsofia-sip-ua
 LINKER=$(CC)
diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c
index 804efd7213..c05a5ccba2 100644
--- a/src/mod/endpoints/mod_sofia/mod_sofia.c
+++ b/src/mod/endpoints/mod_sofia/mod_sofia.c
@@ -1142,15 +1142,17 @@ static switch_status_t sofia_on_hangup(switch_core_session_t *session)
 	channel = switch_core_session_get_channel(session);
 	assert(channel != NULL);
 
-	cause = switch_channel_get_cause(channel);
-	sip_cause = hangup_cause_to_sip(cause);
-
 	tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	assert(tech_pvt != NULL);
 
-	deactivate_rtp(tech_pvt);
+	if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
+		return SWITCH_STATUS_SUCCESS;
+	}
 
-	su_home_deinit(tech_pvt->home);
+	cause = switch_channel_get_cause(channel);
+	sip_cause = hangup_cause_to_sip(cause);
+
+	deactivate_rtp(tech_pvt);
 
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel %s hanging up, cause: %s\n", 
 			  switch_channel_get_name(channel), switch_channel_cause2str(cause), sip_cause);
@@ -1191,6 +1193,11 @@ static switch_status_t sofia_on_hangup(switch_core_session_t *session)
 	switch_set_flag_locked(tech_pvt, TFLAG_BYE);
 	switch_clear_flag_locked(tech_pvt, TFLAG_IO);
 
+	if (tech_pvt->home) {
+		su_home_deinit(tech_pvt->home);
+		tech_pvt->home = NULL;
+	}
+
 	return SWITCH_STATUS_SUCCESS;
 }