<p dir="ltr">Do you any way to check if the channel is already destroyed having pointer to it or querying the originating channel? Basically I need to know if and when the outgoing channel (peer_channel) was anwered.</p>
<div class="gmail_quote">El 28/05/2016 18:53, "Michael Jerris" <<a href="mailto:mike@jerris.com">mike@jerris.com</a>> escribió:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">would need to see the entire module likely to see, but I suspect however this is being called, the channel is already destroyed <br><br>On Saturday, May 28, 2016, Juan Antonio Ibañez Santorum <<a href="mailto:juanito1982@gmail.com" target="_blank">juanito1982@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div> 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:</div><div> </div><div>------------------------------</div><div>status = switch_ivr_originate(session, &peer_session, &cause, cadena_marcado_tmp, 0, NULL, rt->callerid_name, rt->callerid_number, NULL, NULL, SOF_NONE, NULL);</div><div><br></div><div><span style="white-space:pre-wrap">                </span>if(status == SWITCH_STATUS_SUCCESS){</div><div><br></div><div> if (switch_channel_test_flag(caller_channel, CF_PROXY_MODE)) {</div><div><span style="white-space:pre-wrap">                                </span>switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "%s: Llamada switch_ivr_signal_bridge\n", rt->uuid);</div><div><span style="white-space:pre-wrap">                                </span>switch_ivr_signal_bridge(session, peer_session);</div><div><span style="white-space:pre-wrap">                        </span>} else {</div><div><span style="white-space:pre-wrap">                                </span>switch_channel_t *channel = switch_core_session_get_channel(session);</div><div><span style="white-space:pre-wrap">                                </span>switch_channel_t *peer_channel = switch_core_session_get_channel(peer_session);</div><div><span style="white-space:pre-wrap">                                </span>char *a_key = (char *) switch_channel_get_variable(channel, "bridge_terminate_key");</div><div><span style="white-space:pre-wrap">                                </span>char *b_key = (char *) switch_channel_get_variable(peer_channel, "bridge_terminate_key");</div><div><span style="white-space:pre-wrap">                                </span>int ok = 0;</div><div><span style="white-space:pre-wrap">                                </span>//switch_input_callback_function_t func = NULL;</div><div><span style="white-space:pre-wrap">                                </span>rt->peer_channel = peer_channel;</div><div><span style="white-space:pre-wrap">                                </span>rt->peer_profile = switch_channel_get_caller_profile(peer_channel);</div><div><br></div><div><span style="white-space:pre-wrap">                                </span>if (a_key) {</div><div><span style="white-space:pre-wrap">                                        </span>a_key = switch_core_session_strdup(session, a_key);</div><div><span style="white-space:pre-wrap">                                        </span>ok++;</div><div><span style="white-space:pre-wrap">                                </span>}</div><div><span style="white-space:pre-wrap">                                </span>if (b_key) {</div><div><span style="white-space:pre-wrap">                                        </span>b_key = switch_core_session_strdup(session, b_key);</div><div><span style="white-space:pre-wrap">                                        </span>ok++;</div><div><span style="white-space:pre-wrap">                                </span>}</div><div><span style="white-space:pre-wrap">                                </span>if (switch_true(switch_channel_get_variable(caller_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE)) ||</div><div><span style="white-space:pre-wrap">                                        </span>switch_true(switch_channel_get_variable(peer_channel, SWITCH_BYPASS_MEDIA_AFTER_BRIDGE_VARIABLE))) {</div><div><span style="white-space:pre-wrap">                                        </span>switch_channel_set_flag(caller_channel, CF_BYPASS_MEDIA_AFTER_BRIDGE);</div><div><span style="white-space:pre-wrap">                                </span>}</div><div><br></div><div><span style="white-space:pre-wrap">                                </span>switch_core_session_enable_heartbeat(session, rt->heartbeat_interval);<span style="white-space:pre-wrap">        </span></div><div><br></div><div><span style="white-space:pre-wrap">                                </span>// Bridge</div><div><span style="white-space:pre-wrap">                                </span>switch_ivr_multi_threaded_bridge(session, peer_session, NULL, NULL, NULL);</div><div><span style="white-space:pre-wrap">                                </span>if(peer_channel){</div><div><span style="white-space:pre-wrap">                                        </span>if((peer_profile = switch_channel_get_caller_profile(peer_channel))){</div><div><span style="white-space:pre-wrap">                                        </span>}</div><div><span style="white-space:pre-wrap">                                        </span>rt->codec_out = switch_core_strdup(pool, switch_channel_get_variable(peer_channel, "write_codec"));</div><div><span style="white-space:pre-wrap">                                </span>}</div><div><br></div><div><span style="white-space:pre-wrap">                                </span>switch_core_session_disable_heartbeat(session);<span style="white-space:pre-wrap">        </span></div><div><span style="white-space:pre-wrap">                        </span>}</div><div><span style="white-space:pre-wrap">                </span>}</div><div>------------------------------</div><div><br></div><div>At the end of the application function y use this code to do some tasks if the call gets answered:</div><div><br></div><div>------------------------------</div><div>...</div><div> </div><div><span style="white-space:pre-wrap">        </span>if(dc->rt->peer_channel && switch_channel_test_flag(dc->rt->peer_channel, CF_ANSWERED)){</div><div> // Tasks if answered</div><div> }</div><div>...</div><div>------------------------------</div><div><br></div><div><br></div><div>I don't understand why sometimes switch_channel_test_flag generate a segfault. GDB stack trace is:</div><div><br></div><div><br></div><div>------------------------------</div><div>#0 0x00007f2947415420 in pthread_mutex_lock () from /lib64/libpthread.so.0</div><div>#1 0x00007f2948e522f3 in switch_channel_test_flag (channel=0x7f2934558a30,</div><div> flag=CF_ANSWERED) at src/switch_channel.c:1539</div><div>#2 0x00007f292950dcf6 in procesar_hangup (session=0x7f293826b998)</div><div> at /usr/src/instalacion/09freeswitch/freeswitch-1.4.23/src/mod/applications/mod_svbilling/mod_svbilling.c:4743</div><div>#3 0x00007f29295153a8 in do_routing (session=0x7f293826b998)</div><div> at /usr/src/instalacion/09freeswitch/freeswitch-1.4.23/src/mod/applications/mod_svbilling/mod_svbilling.c:3937</div><div>#4 0x00007f2948e7d4d0 in switch_core_session_exec (session=0x7f293826b998,</div><div> application_interface=0xd73208, arg=0x7f293429d550 "process")</div><div> at src/switch_core_session.c:2754</div><div>#5 0x00007f2948e7da32 in switch_core_session_execute_application_get_flags (</div><div> session=0x7f293826b998, app=0x7f293429d540 "svbillingapp",</div><div> arg=0x7f293429d550 "process", flags=<value optimized out>)</div><div> at src/switch_core_session.c:2624</div><div>#6 0x00007f2948e81794 in switch_core_standard_on_execute (</div><div> session=0x7f293826b998) at src/switch_core_state_machine.c:283</div><div>#7 switch_core_session_run (session=0x7f293826b998)</div><div> at src/switch_core_state_machine.c:535</div><div>#8 0x00007f2948e7c23e in switch_core_session_thread (</div><div> thread=<value optimized out>, obj=0x7f293826b998)</div><div> at src/switch_core_session.c:1607</div><div>...</div><div>------------------------------</div><div><br></div><div>The generated core can be downloaded at:</div><div><br></div><div><a href="https://dl.dropboxusercontent.com/u/45510863/coretx/core.zip" target="_blank">https://dl.dropboxusercontent.com/u/45510863/coretx/core.zip</a></div><div><br></div><div>and the line generating the segfault inside switch_channel.c is</div><div><br></div><div>------------------------------ </div><div>switch_mutex_lock(channel->flag_mutex);</div><div>------------------------------</div><div><br></div><div>I suppose I am doing something in a wrong way but I don't know which one. Do anyone knows why?</div><div><br></div><div>Regards</div></div>
</blockquote>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" rel="noreferrer" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://wiki.freeswitch.org" rel="noreferrer" target="_blank">http://wiki.freeswitch.org</a><br>
<a href="http://www.cluecon.com" rel="noreferrer" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-dev mailing list<br>
<a href="mailto:FreeSWITCH-dev@lists.freeswitch.org">FreeSWITCH-dev@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-dev</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-dev" rel="noreferrer" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-dev</a><br>
<a href="http://www.freeswitch.org" rel="noreferrer" target="_blank">http://www.freeswitch.org</a><br>
<br></blockquote></div>