Fix an issue in iax2 where a call that's been rejected still kept an open channel...
[asterisk/asterisk.git] / channels / chan_iax2.c
index 885ad28..71d4137 100644 (file)
@@ -3715,16 +3715,14 @@ static int iax2_call(struct ast_channel *c, char *dest, int timeout)
 static int iax2_hangup(struct ast_channel *c) 
 {
        unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
 static int iax2_hangup(struct ast_channel *c) 
 {
        unsigned short callno = PTR_TO_CALLNO(c->tech_pvt);
-       int alreadygone;
        struct iax_ie_data ied;
        memset(&ied, 0, sizeof(ied));
        ast_mutex_lock(&iaxsl[callno]);
        if (callno && iaxs[callno]) {
                ast_debug(1, "We're hanging up %s now...\n", c->name);
        struct iax_ie_data ied;
        memset(&ied, 0, sizeof(ied));
        ast_mutex_lock(&iaxsl[callno]);
        if (callno && iaxs[callno]) {
                ast_debug(1, "We're hanging up %s now...\n", c->name);
-               alreadygone = ast_test_flag(iaxs[callno], IAX_ALREADYGONE);
                /* Send the hangup unless we have had a transmission error or are already gone */
                iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, (unsigned char)c->hangupcause);
                /* Send the hangup unless we have had a transmission error or are already gone */
                iax_ie_append_byte(&ied, IAX_IE_CAUSECODE, (unsigned char)c->hangupcause);
-               if (!iaxs[callno]->error && !alreadygone) {
+               if (!iaxs[callno]->error && !ast_test_flag(iaxs[callno], IAX_ALREADYGONE)) {
                        send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
                        if (!iaxs[callno]) {
                                ast_mutex_unlock(&iaxsl[callno]);
                        send_command_final(iaxs[callno], AST_FRAME_IAX, IAX_COMMAND_HANGUP, 0, ied.buf, ied.pos, -1);
                        if (!iaxs[callno]) {
                                ast_mutex_unlock(&iaxsl[callno]);
@@ -3734,7 +3732,7 @@ static int iax2_hangup(struct ast_channel *c)
                /* Explicitly predestroy it */
                iax2_predestroy(callno);
                /* If we were already gone to begin with, destroy us now */
                /* Explicitly predestroy it */
                iax2_predestroy(callno);
                /* If we were already gone to begin with, destroy us now */
-               if (alreadygone && iaxs[callno]) {
+               if (iaxs[callno]) {
                        ast_debug(1, "Really destroying %s now...\n", c->name);
                        iax2_destroy(callno);
                }
                        ast_debug(1, "Really destroying %s now...\n", c->name);
                        iax2_destroy(callno);
                }