GNOME Bugzilla – Bug 306249
signal_impl::slots_ leaks slots
Last modified: 2005-06-07 13:46:43 UTC
Version details: 2.0.11 Distribution/Version: XP SP2 with MSVC .NET 2003 (7.1) Disconnecting a connection while the corresponding signal (without an accumulator) is emitted leaks the related slot_base instance. The reason is that struct signal_emit2<T_return, T_arg1,T_arg2, nil>::emit (in signal.h) relies on a specific sequence of destructor calls for the automatic variables 'exec' (of type signal_exec) and 'slots' (of type temp_slot_list). Unfortunately my compiler has it the 'wrong' way around. I attach a hack which works around this but I don't believe it's worth to be checked in because: * it is ugly * it only handles signal_emit2 while I think that the other signal_emit# classes have the same problem (in the specialisation without accumulator) * as Bug 303896 and other recent discussions, IMHO, seem to suggest, the current semantics of connecting and disconnecting slots during emission seems to warrant a more profound reimplementation and I seem to have read that something like that is underway (?)
Created attachment 47134 [details] [review] A quick hack as workaround
signal.h is a generated file. Please try to submit a cvs patch, changing the .m4 file, and also patching the ChangeLog. For instance, cvs -z3 diff -up > something.patch. A test case would be nice too.
Oops, you're right, I've forgotten to mention that my 'patch' is diffed against 2.0.11. Sorry for any confusion cuased by that. Diffing against cvs unfortunately doesn't work for me by courtesy of a corporate firewall. Sorry for that. The hack is to just introduce a new inner scope in which 'slots' is created. Thus it is ensured that its destructor is called before 'exec's destructor. A simple test case is attached.
Created attachment 47308 [details] Simple test case to demonstrate the bug.
BTW: This also happens with cygwin's g++ (version 3.3.3 (cygwin special)) and libsigc++ 2.0.10.
Thanks, I've applied basically the same thing to the .m4 file. The test case failed on my Fedora Core 3 g++ 3.4 too.