Boost C++ Libraries: Ticket #2932: iostreams file_descriptor: possible throw of exception in call to destructor https://svn.boost.org/trac10/ticket/2932 <p> The implementation "struct file_descriptor_impl" used by "class file_descriptor" possibly throws an exception in its destructor. </p> <p> The following code snippets come from: <a class="ext-link" href="http://svn.boost.org/svn/boost/trunk/libs/iostreams/src/file_descriptor.cpp"><span class="icon">​</span>http://svn.boost.org/svn/boost/trunk/libs/iostreams/src/file_descriptor.cpp</a> </p> <p> line 77: </p> <pre class="wiki">file_descriptor_impl::~file_descriptor_impl() { if (flags_ &amp; close_on_exit) close(); } </pre><p> line 194: </p> <pre class="wiki">void file_descriptor_impl::close() ... if (!success) throw_system_failure("failed closing file"); ... </pre><p> IMHO throwing exceptions in destructors should be avoided. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2932 Trac 1.4.3 Gareth Sylvester-Bradley <gareth.sylvester-bradley@…> Thu, 30 Jul 2009 08:41:45 GMT cc, severity, milestone changed https://svn.boost.org/trac10/ticket/2932#comment:1 https://svn.boost.org/trac10/ticket/2932#comment:1 <ul> <li><strong>cc</strong> <span class="trac-author">gareth.sylvester-bradley@…</span> added </li> <li><strong>severity</strong> <span class="trac-field-old">Problem</span> → <span class="trac-field-new">Showstopper</span> </li> <li><strong>milestone</strong> <span class="trac-field-old">Boost 1.39.0</span> → <span class="trac-field-new">Boost 1.40.0</span> </li> </ul> <blockquote class="citation"> <p> IMHO throwing exceptions in destructors should be avoided. </p> </blockquote> <p> I'd put it stronger than that! This just bit my product for real, causing a std::terminate() due to an exception from this destructor during stack unwinding for another exception (in fact a "bad close" from an explicit call to close() on the same stream). </p> <p> FWIW, I was using the 1.39.0 release, where the problem is present here - </p> <p> <a class="ext-link" href="https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/iostreams/device/file_descriptor.hpp#L89"><span class="icon">​</span>https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/iostreams/device/file_descriptor.hpp#L89</a> </p> <pre class="wiki"> ~impl() { if (flags_ &amp; close_on_exit) close_impl(*this); } </pre><p> IMHO, this needs to be patched ASAP. </p> Ticket Marshall Clow Mon, 30 Nov 2009 01:03:30 GMT <link>https://svn.boost.org/trac10/ticket/2932#comment:2 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2932#comment:2</guid> <description> <p> This issue was patched 6 months ago. The fix is in the 1.41.0 release. is it time to close this bug? </p> </description> <category>Ticket</category> </item> <item> <author>Gareth Sylvester-Bradley <gareth.sylvester-bradley@…></author> <pubDate>Mon, 30 Nov 2009 09:01:33 GMT</pubDate> <title>status, version changed; resolution set https://svn.boost.org/trac10/ticket/2932#comment:3 https://svn.boost.org/trac10/ticket/2932#comment:3 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>version</strong> <span class="trac-field-old">Boost Development Trunk</span> → <span class="trac-field-new">Boost 1.41.0</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> Replying to <a class="ticket" href="https://svn.boost.org/trac10/ticket/2932#comment:2" title="Comment 2">marshall</a>: </p> <blockquote class="citation"> <p> This issue was patched 6 months ago. The fix is in the 1.41.0 release. is it time to close this bug? </p> </blockquote> <p> Marshall, I'm not sure to whom your question was addressed, but as one of the reporters, the version in 1.41.0 looks good to me; hope it's ok that I'm changing resolution to 'fixed'. Many thanks to Beman that the fix didn't languish on the trunk for <em>more</em> than six months! </p> Ticket