Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 40871) +++ channels/chan_sip.c (working copy) @@ -1465,7 +1465,6 @@ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e); static void handle_request_info(struct sip_pvt *p, struct sip_request *req); static int handle_request_options(struct sip_pvt *p, struct sip_request *req); -static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin); static int handle_request_notify(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e); static int handle_invite_replaces(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, int seqno, struct sockaddr_in *sin); static int local_attended_transfer(struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno); @@ -12503,7 +12502,7 @@ ast_mutex_unlock(&p->refer->refer_call->lock); /* Make sure that the masq does not free our PVT for the old call */ - ast_set_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ + ast_set_flag(&p->refer->refer_call->flags[0], AST_FLAG_KEEP_PVT_AT_HANGUP); /* Delay hangup */ /* Prepare the masquerade - if this does not happen, we will be gone */ if(ast_channel_masquerade(replacecall, c)) Index: include/asterisk/channel.h =================================================================== --- include/asterisk/channel.h (revision 40871) +++ include/asterisk/channel.h (working copy) @@ -466,6 +466,8 @@ AST_FLAG_OUTGOING = (1 << 10), /*! This channel is being whispered on */ AST_FLAG_WHISPER = (1 << 11), + /*! Do NOT destroy PVT even if it's around after hangup! */ + AST_FLAG_KEEP_PVT_AT_HANGUP = (1 << 12), }; /*! \brief ast_bridge_config flags */ Index: main/channel.c =================================================================== --- main/channel.c (revision 40871) +++ main/channel.c (working copy) @@ -987,8 +987,12 @@ ast_channel_lock(chan); ast_channel_unlock(chan); if (chan->tech_pvt) { - ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); - free(chan->tech_pvt); + if (ast_test_flag(chan, AST_FLAG_KEEP_PVT_AT_HANGUP)) { + ast_log(LOG_DEBUG, "Channel '%s' pvt stays around, even though the channel is freed.\n", chan->name); + } else { + ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); + free(chan->tech_pvt); + } } if (chan->sched)