Opened 14 years ago

Closed 13 years ago

#2932 closed Bugs (fixed)

iostreams file_descriptor: possible throw of exception in call to destructor

Reported by: Robert Hunger <rhunger@…> Owned by: Jonathan Turkanis
Milestone: Boost 1.40.0 Component: iostreams
Version: Boost 1.41.0 Severity: Showstopper
Keywords: Cc: rhunger@…, gareth.sylvester-bradley@…

Description

The implementation "struct file_descriptor_impl" used by "class file_descriptor" possibly throws an exception in its destructor.

The following code snippets come from: http://svn.boost.org/svn/boost/trunk/libs/iostreams/src/file_descriptor.cpp

line 77:

file_descriptor_impl::~file_descriptor_impl() 
{ if (flags_ & close_on_exit) close(); }

line 194:

void file_descriptor_impl::close()
...
        if (!success)
            throw_system_failure("failed closing file");
...

IMHO throwing exceptions in destructors should be avoided.

Change History (3)

comment:1 by Gareth Sylvester-Bradley <gareth.sylvester-bradley@…>, 13 years ago

Cc: gareth.sylvester-bradley@… added
Milestone: Boost 1.39.0Boost 1.40.0
Severity: ProblemShowstopper

IMHO throwing exceptions in destructors should be avoided.

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).

FWIW, I was using the 1.39.0 release, where the problem is present here -

https://svn.boost.org/trac/boost/browser/tags/release/Boost_1_39_0/boost/iostreams/device/file_descriptor.hpp#L89

       ~impl()
        { if (flags_ & close_on_exit) close_impl(*this); }

IMHO, this needs to be patched ASAP.

comment:2 by Marshall Clow, 13 years ago

This issue was patched 6 months ago. The fix is in the 1.41.0 release. is it time to close this bug?

in reply to:  2 comment:3 by Gareth Sylvester-Bradley <gareth.sylvester-bradley@…>, 13 years ago

Resolution: fixed
Status: newclosed
Version: Boost Development TrunkBoost 1.41.0

Replying to marshall:

This issue was patched 6 months ago. The fix is in the 1.41.0 release. is it time to close this bug?

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 more than six months!

Note: See TracTickets for help on using tickets.