would need to see the entire module likely to see, but I suspect however this is being called, the channel is already destroyed On Saturday, May 28, 2016, Juan Antonio Ibañez Santorum < juanito1982@gmail.com> wrote:
Hello,
I built one module similar to mod_niblebill for billing puroses. It works ok but sometimes I get a segfault and I don't understand why. The code I use in my application for generating outgoing session is:
------------------------------ status = switch_ivr_originate(session, &peer_session, &cause, cadena_marcado_tmp, 0, NULL, rt->callerid_name, rt->callerid_number, NULL, NULL, SOF_NONE, NULL);
if(status == SWITCH_STATUS_SUCCESS){
if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s: Llamada switch_ivr_signal_bridge\n", rt->uuid); switch_ivr_signal_bridge(session, peer_session); } else { switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session); char *a_key = (char *) switch_channel_get_variable(channel, "bridge_terminate_key"); char *b_key = (char *) switch_channel_get_variable(peer_channel, "bridge_terminate_key"); int ok = 0; //switch_input_callback_function_t func = NULL; rt->peer_channel = peer_channel; rt->peer_profile = switch_channel_get_caller_profile(peer_channel);
if (a_key) { a_key = switch_core_session_strdup(session, a_key); ok++; } if (b_key) { b_key = switch_core_session_strdup(session, b_key); ok++; } if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE)) || switch_true(switch_channel_get_variable(peer_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE))) { switch_channel_set_flag(caller_channel, CF_BYPASS_MEDIA_AFTER_BRIDGE); }
switch_core_session_enable_heartbeat(session, rt->heartbeat_interval);
// Bridge switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL); if(peer_channel){ if((peer_profile = switch_channel_get_caller_profile(peer_channel))){ } rt->codec_out = switch_core_strdup(pool, switch_channel_get_variable(peer_channel, "write_codec")); }
switch_core_session_disable_heartbeat(session); } } ------------------------------
At the end of the application function y use this code to do some tasks if the call gets answered:
------------------------------ ...
if(dc->rt->peer_channel && switch_channel_test_flag(dc->rt->peer_channel, CF_ANSWERED)){ // Tasks if answered } ... ------------------------------
I don't understand why sometimes switch_channel_test_flag generate a segfault. GDB stack trace is:
------------------------------ #0 0x00007f2947415420 in pthread_mutex_lock () from /lib64/libpthread.so.0 #1 0x00007f2948e522f3 in switch_channel_test_flag (channel=0x7f2934558a30, flag=CF_ANSWERED) at src/switch_channel.c:1539 #2 0x00007f292950dcf6 in procesar_hangup (session=0x7f293826b998) at /usr/src/instalacion/09freeswitch/freeswitch-1.4.23/src/mod/applications/mod_svbilling/mod_svbilling.c:4743 #3 0x00007f29295153a8 in do_routing (session=0x7f293826b998) at /usr/src/instalacion/09freeswitch/freeswitch-1.4.23/src/mod/applications/mod_svbilling/mod_svbilling.c:3937 #4 0x00007f2948e7d4d0 in switch_core_session_exec (session=0x7f293826b998, application_interface=0xd73208, arg=0x7f293429d550 "process") at src/switch_core_session.c:2754 #5 0x00007f2948e7da32 in switch_core_session_execute_application_get_flags ( session=0x7f293826b998, app=0x7f293429d540 "svbillingapp", arg=0x7f293429d550 "process", flags=<value optimized out>) at src/switch_core_session.c:2624 #6 0x00007f2948e81794 in switch_core_standard_on_execute ( session=0x7f293826b998) at src/switch_core_state_machine.c:283 #7 switch_core_session_run (session=0x7f293826b998) at src/switch_core_state_machine.c:535 #8 0x00007f2948e7c23e in switch_core_session_thread ( thread=<value optimized out>, obj=0x7f293826b998) at src/switch_core_session.c:1607 ... ------------------------------
The generated core can be downloaded at:
https://dl.dropboxusercontent.com/u/45510863/coretx/core.zip
and the line generating the segfault inside switch_channel.c is
------------------------------ switch_mutex_lock(channel->flag_mutex); ------------------------------
I suppose I am doing something in a wrong way but I don't know which one. Do anyone knows why?
Regards