]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
freetdm: fix segfault in socket mode boost unload
authorMoises Silva <moy@sangoma.com>
Mon, 10 May 2010 17:02:17 +0000 (13:02 -0400)
committerMoises Silva <moy@sangoma.com>
Mon, 10 May 2010 17:03:22 +0000 (13:03 -0400)
libs/freetdm/src/ftmod/ftmod_sangoma_boost/ftmod_sangoma_boost.c

index b102a741426e409b92d2b58b1221e533990f01f9..bc0df8d4a890b98ce8f60132856ef3968f62722d 100644 (file)
@@ -2176,24 +2176,31 @@ static ftdm_status_t ftdm_sangoma_boost_start(ftdm_span_t *span)
 
 static ftdm_status_t ftdm_sangoma_boost_stop(ftdm_span_t *span)
 {
-       int cnt = 10;
+       int cnt = 50;
        ftdm_status_t status = FTDM_SUCCESS;
        ftdm_sangoma_boost_data_t *sangoma_boost_data = span->signal_data;
        if (sangoma_boost_data->sigmod) {
-
-               /* FIXME: we should make sure the span thread is stopped (use pthread_kill or freetdm thread kill function) */
                /* I think stopping the span before destroying the queue makes sense
                   otherwise may be boost events would still arrive when the queue is already destroyed! */
                status = sangoma_boost_data->sigmod->stop_span(span);
-
                ftdm_queue_enqueue(sangoma_boost_data->boost_queue, NULL);
-               while(ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING) && cnt-- > 0) {
-                       ftdm_log(FTDM_LOG_DEBUG, "Waiting for boost thread\n");
-                       ftdm_sleep(500);
-               }
-               ftdm_queue_destroy(&sangoma_boost_data->boost_queue);
                return status;
        }
+
+       while (ftdm_test_flag(sangoma_boost_data, FTDM_SANGOMA_BOOST_RUNNING) && cnt-- > 0) {
+               ftdm_log(FTDM_LOG_DEBUG, "Waiting for boost thread\n");
+               ftdm_sleep(100);
+       }
+
+       if (!cnt) {
+               ftdm_log(FTDM_LOG_CRIT, "it seems boost thread in span %s may be stuck, we may segfault :-(\n", span->name);
+               return FTDM_FAIL;
+       }
+
+       if (sangoma_boost_data->sigmod) {
+               ftdm_queue_destroy(&sangoma_boost_data->boost_queue);
+       }
+
        return status;
 }