Boost C++ Libraries: Ticket #7275: SIGSEGV in boost::asio::connect when compiled with g++ -std=c++0x https://svn.boost.org/trac10/ticket/7275 <p> Works fine when not compiled with -std=c++0x. GCC v. 4.6.3 on ubuntu 12.04 Linking to static libboost_thread, libboost_system (1.50.0 release config) Does not matter if server code is listening or not. </p> <p> Minimal reproducible code below: </p> <p> int main(int argc, char *argv[]) { </p> <blockquote> <p> boost::asio::io_service service; </p> </blockquote> <blockquote> <p> using namespace boost::asio::ip; </p> </blockquote> <blockquote> <p> tcp::resolver resolver(service); tcp::resolver::query query(tcp::v4(), "127.0.0.1", "50001"); tcp::resolver::iterator itr = resolver.resolve(query); </p> </blockquote> <blockquote> <p> if (itr != tcp::resolver::iterator()) { </p> <blockquote> <p> tcp::socket s(service); boost::asio::connect(s, itr); <em> Segmentation Fault Here </em></p> </blockquote> <p> } </p> </blockquote> <p> } </p> <p> Callstack: </p> <p> <a class="missing ticket">#0</a> 0x8054d6e boost::asio::detail::reactive_socket_service_base::close(this=0x16, impl=..., ec=...) (reactive_socket_service_base.ipp:103) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/1" title="#1: Bugs: boost.build causes ftjam to segfault (closed: Wont Fix)">#1</a> 0x8058f1a boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;::close(this=0x2, impl=..., ec=...) (stream_socket_service.hpp:151) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2" title="#2: Bugs: list::size should be const (closed: fixed)">#2</a> 0x80589d5 boost::asio::basic_socket&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt; &gt;::close(this=0xbffff318, ec=...) (basic_socket.hpp:339) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/3" title="#3: Bugs: automatic conversion and overload proble (closed: fixed)">#3</a> 0x8058186 boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt;, boost::asio::detail::default_connect_condition&gt;(s=..., begin=..., end=..., connect_condition=..., ec=...) (connect.hpp:120) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/4" title="#4: Bugs: any_ptr in any library documentation? (closed: Fixed)">#4</a> 0x80578a5 boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt; &gt;(s=..., begin=..., ec=...) (connect.hpp:56) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/5" title="#5: Bugs: shared_ptr and self-owning objects (closed: Fixed)">#5</a> 0x8056dd2 boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt; &gt;(s=..., begin=...) (connect.hpp:47) <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/6" title="#6: Bugs: tie in utility.hpp and tuple.hpp clash. (closed: Duplicate)">#6</a> 0x8052f41 main(argc=1, argv=0xbffff874) (main.cpp:27) </p> <p> Thank you. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/7275 Trac 1.4.3 Alan Yuelkenbeck <ayuelkenbeck@…> Fri, 24 Aug 2012 16:12:31 GMT <link>https://svn.boost.org/trac10/ticket/7275#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/7275#comment:1</guid> <description> <h1 class="section" id="Fixedtheformatting">Fixed the formatting</h1> <ul><li>Works fine when not compiled with -std=c++0x. </li><li>GCC v. 4.6.3 on ubuntu 12.04 </li><li>Linking to static libboost_thread, libboost_system (1.50.0 release config) </li><li>Does not matter if server code is listening or not. </li></ul><p> Minimal reproducible code below: </p> <div class="wiki-code"><div class="code"><pre><span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">argv</span><span class="p">[])</span> <span class="p">{</span> <span class="n">boost</span><span class="o">::</span><span class="n">asio</span><span class="o">::</span><span class="n">io_service</span> <span class="n">service</span><span class="p">;</span> <span class="k">using</span> <span class="k">namespace</span> <span class="n">boost</span><span class="o">::</span><span class="n">asio</span><span class="o">::</span><span class="n">ip</span><span class="p">;</span> <span class="n">tcp</span><span class="o">::</span><span class="n">resolver</span> <span class="n">resolver</span><span class="p">(</span><span class="n">service</span><span class="p">);</span> <span class="n">tcp</span><span class="o">::</span><span class="n">resolver</span><span class="o">::</span><span class="n">query</span> <span class="n">query</span><span class="p">(</span><span class="n">tcp</span><span class="o">::</span><span class="n">v4</span><span class="p">(),</span> <span class="s">&quot;127.0.0.1&quot;</span><span class="p">,</span> <span class="s">&quot;50001&quot;</span><span class="p">);</span> <span class="n">tcp</span><span class="o">::</span><span class="n">resolver</span><span class="o">::</span><span class="n">iterator</span> <span class="n">itr</span> <span class="o">=</span> <span class="n">resolver</span><span class="p">.</span><span class="n">resolve</span><span class="p">(</span><span class="n">query</span><span class="p">);</span> <span class="k">if</span> <span class="p">(</span><span class="n">itr</span> <span class="o">!=</span> <span class="n">tcp</span><span class="o">::</span><span class="n">resolver</span><span class="o">::</span><span class="n">iterator</span><span class="p">())</span> <span class="p">{</span> <span class="n">tcp</span><span class="o">::</span><span class="n">socket</span> <span class="n">s</span><span class="p">(</span><span class="n">service</span><span class="p">);</span> <span class="n">boost</span><span class="o">::</span><span class="n">asio</span><span class="o">::</span><span class="n">connect</span><span class="p">(</span><span class="n">s</span><span class="p">,</span> <span class="n">itr</span><span class="p">);</span> <span class="c1">// Segmentation Fault Here</span> <span class="p">}</span> <span class="p">}</span> </pre></div></div><p> Callstack: </p> <pre class="wiki">boost::asio::detail::reactive_socket_service_base::close(this=0x16, impl=..., ec=...) (reactive_socket_service_base.ipp:103) boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;::close(this=0x2, impl=..., ec=...) (stream_socket_service.hpp:151) boost::asio::basic_socket&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt; &gt;::close(this=0xbffff318, ec=...) (basic_socket.hpp:339) boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt;, boost::asio::detail::default_connect_condition&gt;(s=..., begin=..., end=..., connect_condition=..., ec=...) (connect.hpp:120) boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt; &gt;(s=..., begin=..., ec=...) (connect.hpp:56) boost::asio::connect&lt;boost::asio::ip::tcp, boost::asio::stream_socket_service&lt;boost::asio::ip::tcp&gt;, boost::asio::ip::basic_resolver_iterator&lt;boost::asio::ip::tcp&gt; &gt;(s=..., begin=...) (connect.hpp:47) main(argc=1, argv=0xbffff874) (main.cpp:27) </pre><p> Thank you. </p> </description> <category>Ticket</category> </item> </channel> </rss>