From 81bfe43589caac269c363881c43b5dd7bea699f0 Mon Sep 17 00:00:00 2001
From: Marc Olivier Chouinard <mochouinard@moctel.com>
Date: Fri, 25 Mar 2011 15:50:52 -0400
Subject: [PATCH] mod_sofia: Correct a problem where restarting profile would
 cause some profile hash entry to remain.

---
 src/mod/endpoints/mod_sofia/sofia_glue.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c
index cbb8cb3485..acb0a05aaa 100644
--- a/src/mod/endpoints/mod_sofia/sofia_glue.c
+++ b/src/mod/endpoints/mod_sofia/sofia_glue.c
@@ -5210,12 +5210,14 @@ void sofia_glue_del_profile(sofia_profile_t *profile)
 		}
 
 		for (gp = profile->gateways; gp; gp = gp->next) {
+			char *pkey = switch_mprintf("%s::%s", profile->name, gp->name);
+
 			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gp->name);
-			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gp->register_from);
-			switch_core_hash_delete(mod_sofia_globals.gateway_hash, gp->register_contact);
-			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "deleted gateway %s\n", gp->name);
-			profile->gateways = NULL;
+			switch_core_hash_delete(mod_sofia_globals.gateway_hash, pkey);
+			switch_safe_free(pkey);
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "deleted gateway %s from profile %s\n", gp->name, profile->name);
 		}
+		profile->gateways = NULL;
 	}
 	switch_mutex_unlock(mod_sofia_globals.hash_mutex);
 }