From 0d5e318cb2fc3d8dbc6547f2d30a6f7f5ea90a60 Mon Sep 17 00:00:00 2001
From: Jeff Peeler <jpeeler@digium.com>
Date: Tue, 15 Sep 2009 16:12:49 +0000
Subject: [PATCH] Add some changes related to 218430.

* Remove thread_spawned in handle_init_event since it was never used
* Always check handle_init_event in case a channel is destroyed


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@218583 65c4cc65-6c06-0410-ace0-fbb531ad65f3
---
 channels/chan_dahdi.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/channels/chan_dahdi.c b/channels/chan_dahdi.c
index 1c84511dfa..28fa20055f 100644
--- a/channels/chan_dahdi.c
+++ b/channels/chan_dahdi.c
@@ -9922,7 +9922,6 @@ static int dahdi_destroy_channel_bynum(int channel)
 static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event)
 {
 	int res;
-	int thread_spawned = 0;
 	pthread_t threadid;
 	struct ast_channel *chan;
 
@@ -9976,8 +9975,6 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event)
 						if (res < 0)
 							ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
 						ast_hangup(chan);
-					} else {
-						thread_spawned = 1;
 					}
 				} else
 					ast_log(LOG_WARNING, "Unable to create channel\n");
@@ -10019,8 +10016,6 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event)
 					ast_log(LOG_WARNING, "Unable to play congestion tone on channel %d\n", i->channel);
 				}
 				ast_hangup(chan);
-			} else {
-				thread_spawned = 1;
 			}
 			break;
 		default:
@@ -10109,8 +10104,6 @@ static struct dahdi_pvt *handle_init_event(struct dahdi_pvt *i, int event)
 					ast_log(LOG_WARNING, "Cannot allocate new structure on channel %d\n", i->channel);
 				} else if (ast_pthread_create_detached(&threadid, NULL, analog_ss_thread, chan)) {
 					ast_log(LOG_WARNING, "Unable to start simple switch thread on channel %d\n", i->channel);
-				} else {
-					thread_spawned = 1;
 				}
 			}
 			break;
@@ -10363,7 +10356,8 @@ static void *do_monitor(void *data)
 									struct ast_channel *chan;
 									ast_mutex_unlock(&iflock);
 									if (analog_lib_handles(i->sig, i->radio, i->oprmode)) {
-										analog_handle_init_event(i->sig_pvt, ANALOG_EVENT_DTMFCID);  
+										/* just in case this event changes or somehow destroys a channel, set doomed here too */
+										doomed = analog_handle_init_event(i->sig_pvt, ANALOG_EVENT_DTMFCID);  
 										i->dtmfcid_holdoff_state = 1;
 									} else {
 										chan = dahdi_new(i, AST_STATE_PRERING, 0, SUB_REAL, 0, 0, NULL);
-- 
GitLab