This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: C++ app segfaults in libstdc++
- From: Dave Korn <dave dot korn dot cygwin at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 17 Jun 2010 13:15:43 +0100
- Subject: Re: C++ app segfaults in libstdc++
- References: <4C198B44.6040803@cwilson.fastmail.fm>
On 17/06/2010 03:41, Charles Wilson wrote:
> Any ideas?
Yes, I have one:
> catch (modexc e) {
> std::cerr << "caught: " << e.what () << '\n';
> if (dlclose (handle))
> {
> std::cerr << "dlclose failed: " << dlerror () << '\n';
> return 1;
> }
> return 0;
> }
You're unloading the module, before the exception that it threw goes out of
scope.
At this time, the modexc object e has not yet been destructed, the catch is
still 'live', and when you attempt to exit the catch block, __cxa_end_catch
gets fatally confused. The live exception still contains pointers into where
the dll used to be loaded: it has typeinfo there, and a pointer to the
module's inlined instance of the ~modexc() dtor.
I think the rule is: Don't unload a shared library while you still have a
live C++ object from it, unless that object is a POD.
cheers,
DaveK
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple