From bb0187ba9462db626c02dae4925036f20b6e5cfb Mon Sep 17 00:00:00 2001
From: Kapil Gupta <kgupta@sangoma.com>
Date: Fri, 10 Aug 2012 12:23:03 -0400
Subject: [PATCH] fixing issue

---
 src/mod/endpoints/mod_media_gateway/media_gateway.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/mod/endpoints/mod_media_gateway/media_gateway.c b/src/mod/endpoints/mod_media_gateway/media_gateway.c
index 3590762cb5..3b12dadfeb 100644
--- a/src/mod/endpoints/mod_media_gateway/media_gateway.c
+++ b/src/mod/endpoints/mod_media_gateway/media_gateway.c
@@ -143,6 +143,7 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
         /* A UUID is present, check if the channel still exists */
         switch_core_session_t *session;
         if ((session = switch_core_session_locate(term->uuid))) {
+	    switch_channel_t *channel = switch_core_session_get_channel(session);
             switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "command", "media_modify");
             
             switch_core_session_receive_event(session, &var_event);
@@ -373,6 +374,7 @@ void megaco_termination_destroy(mg_termination_t *term)
         free(term->active_events);
         term->active_events = NULL;
     }
+    term->context = NULL;
 
     switch_clear_flag(term, MGT_ALLOCATED);
     switch_clear_flag(term, MGT_ACTIVE);
@@ -412,6 +414,7 @@ switch_status_t megaco_context_add_termination(mg_context_t *ctx, mg_termination
         return SWITCH_STATUS_FALSE;
     }
     
+    term->context = ctx;
     if (ctx->terminations[0]) {
         ctx->terminations[1] = term;
     } else if (ctx->terminations[1]) {