<br><br>Sent via the HTC V..b.livid™, anbURL: <a href="http://maps.google.com/maps?q=40.031769,-105.2;Kn">http://maps.google.com/maps?q=40.031769,-105.2;Kn</a>)na?bks3213, 3128 Bell Dr, Boulder, CO 80301, USA AT&T 4G -3$/-)44+$LTE( (::,2mk:<br><br>----- Reply message -----<br>From: "Christian Gagneraud" <chris@techworks.ie><br>To: "Dimitri Stolnikov" <horiz0n@gmx.net><br>Cc: <discuss-gnuradio@gnu.org>, <osmocom-sdr@lists.osmocom.org><br>Subject: [Discuss-gnuradio] FCD/Alsa bug (Re: Bug hunting)<br>Date: Wed, Aug 8, 2012 9:02 am<br><br><br>Cross posting to discuss-gnuradio.<br><br>The bug in question is that if you instanciate an alsa source on a busy device (opened by another app), then the program crashed.<br><br>On 08/08/12 00:23, Dimitri Stolnikov wrote:<br>> Hi Christian,<br>[...]<br>><br>> The other problem (segfault on trow in ctor) still has to be addressed.<br><br>Yes, I started to investigate, and it seems to me that this is not a gr-osmosdr bug, but it's a gnuradio one, caused by gr-fcd.<br><br>This simple test program have the same problem, yet it only uses gr-fcd.<br><br>#include <iostream><br>#include <fcd_source_c.h><br>int main(int argc, char **argv)<br>{<br>    fcd_source_c_sptr fsrc;<br>    try {<br>       fsrc = fcd_make_source_c("hw:2"); // KO, from gr-fcd<br>    }<br>    catch (std::runtime_error &e) {<br>    std::cerr << "Error!\n";<br>    }<br>    exit(0);<br>}<br><br>g++ test.cc -o test -I/usr/local/include/gnuradio -lgnuradio-fcd<br><br>Here is the log:<br>audio_alsa_source[hw:2]: Device or resource busy<br>Error!<br>*** glibc detected *** /home/cgagneraud/sdr/gr-osmosdr/test: free(): invalid pointer: 0x08052e3c ***<br>[...]<br><br>And here is a cleaned up backtrace:<br>operator delete<br>gruel::msg_accepter::~msg_accepter<br>checked_delete<gr_hier_block2><br>boost::detail::sp_counted_impl_p<gr_hier_block2>::dispose<br>[...]<br>const, boost::shared_ptr<gr_basic_block> > > >::~map<br>__cxa_finalize<br>__do_global_dtors_aux<br>[...]<br>main<br><br>The problem is related to gnuradio-core/src/lib/runtime/gr_sptr_magic.{h,cc} and the static std::map in there.<br><br>gr_hier_block2 ctor insert "this" in this map, but then in fcd_source ctor, audio_alsa_source ctor throws an exception, so "this" (gr_hier_block2/fcd_source) is not a valid pointer anymore.<br>When the program exits, the map get cleanup up and free is called on this pointer.<br><br>It's not possible to cleanup the map in fcd_source, because the dtor is not called when exception occurs in the ctor (which, btw, leads to some memory leaks in alsa_source: namely d_hw_params and d_sw_params).<br>It's a bad idea to call fetch_initial_sptr(this) before throwing in the ctor, because it seems the object get deleted.<br><br>