From e401b1469fee10ec6508aca5d2cc1ceba0d35cf0 Mon Sep 17 00:00:00 2001 From: Moises Silva Date: Wed, 24 Jun 2015 01:50:34 -0400 Subject: [PATCH] freetdm: Fix gsm hangup race --- libs/freetdm/src/ftmod/ftmod_gsm/ftmod_gsm.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/freetdm/src/ftmod/ftmod_gsm/ftmod_gsm.c b/libs/freetdm/src/ftmod/ftmod_gsm/ftmod_gsm.c index 4b8c9b6df7..6eb194f067 100755 --- a/libs/freetdm/src/ftmod/ftmod_gsm/ftmod_gsm.c +++ b/libs/freetdm/src/ftmod/ftmod_gsm/ftmod_gsm.c @@ -193,7 +193,8 @@ int on_wat_span_write(unsigned char span_id, void *buffer, unsigned len) gsm_data = span->signal_data; status = ftdm_channel_write(gsm_data->dchan, (void *)buffer, len, &outsize); if (status != FTDM_SUCCESS) { - ftdm_log(FTDM_LOG_ERROR, "Failed to write %d bytes to d-channel in span %s\n", len, span->name); + char errbuf[255]; + ftdm_log(FTDM_LOG_ERROR, "Failed to write %d bytes to d-channel in span %s: %s\n", len, span->name, strerror_r(errno, errbuf, sizeof(errbuf))); return -1; } return len; @@ -345,13 +346,16 @@ void on_wat_rel_ind(unsigned char span_id, uint8_t call_id, wat_rel_event_t *rel ftdm_log(FTDM_LOG_INFO, "s%d: Call hangup (id:%d) cause:%d\n", span_id, call_id, rel_event->cause); - if(!(span = GetSpanByID(span_id, &gsm_data))) { + if (!(span = GetSpanByID(span_id, &gsm_data))) { + return; + } + + if (gsm_data->bchan->state == FTDM_CHANNEL_STATE_HANGUP || + gsm_data->bchan->state == FTDM_CHANNEL_STATE_DOWN) { return; } ftdm_set_state(gsm_data->bchan, FTDM_CHANNEL_STATE_HANGUP); - - } void on_wat_rel_cfm(unsigned char span_id, uint8_t call_id)