GNOME Bugzilla – Bug 676119
Deletion of a Glib dispatcher (in the gtk thread as well) causes segfault
Last modified: 2012-05-31 14:05:06 UTC
I have some multithread code where I use dispatchers. I was carefull in making the dispatchers created / destroyed in the gtk thread. However, its seems that they cannot be destroyed even from there. Please see this code (which is even single thread). Am I missing something? #include <gtkmm.h> #include <iostream> using namespace std; class HelloWorld:public Gtk::Window { public: Glib::Dispatcher* disp; Glib::Dispatcher disp2; sigc::connection conn; void onDisp(){ cout << "Hello by disp" << endl; } HelloWorld():m_button("Hello"),m_destr("Destr") { disp=new Glib::Dispatcher(); sigc::connection conn=disp->connect(sigc::mem_fun(*this,&HelloWorld::onDisp)); disp2.connect(sigc::mem_fun(*this,&HelloWorld::on_work)); m_button.signal_clicked().connect(sigc::mem_fun(*this,&HelloWorld::on_button_clicked)); m_destr.signal_clicked().connect(sigc::mem_fun(*this,&HelloWorld::on_destr_clicked)); v.add(m_button); v.add(m_destr); add(v); show_all_children(); } protected: void on_work(){ usleep(1*1E5); } void on_button_clicked(){ for (size_t i=0;i<100;i++){ if (disp!=NULL){ (*disp)(); } disp2(); } } void on_destr_clicked() { conn.disconnect(); delete disp; disp=NULL; } Gtk::Button m_button; Gtk::Button m_destr; Gtk::VBox v; }; int main (int argc, char *argv[]) { Gtk::Main kit(argc, argv); HelloWorld helloworld; //Shows the window and returns when it is closed. Gtk::Main::run(helloworld); return 0; }
Glib::Dispatcher is a glibmm object - reassigning
valgrind Invalid read of size 8 ==5254== at 0x5931E81: Glib::DispatchNotifier::pipe_io_handler(Glib::IOCondition) (in /usr/lib/libglibmm-2.4.so.1.3.0) ==5254== by 0x5933DCB: Glib::IOSource::dispatch(sigc::slot_base*) (in /usr/lib/libglibmm-2.4.so.1.3.0) ==5254== by 0x59339DE: Glib::Source::dispatch_vfunc(_GSource*, int (*)(void*), void*) (in /usr/lib/libglibmm-2.4.so.1.3.0) ==5254== by 0x7B35A5C: g_main_context_dispatch (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3000.0) ==5254== by 0x7B36257: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3000.0) ==5254== by 0x7B36791: g_main_loop_run (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.3000.0) ==5254== by 0x70E6DB6: gtk_main (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.6) ==5254== by 0x530B325: Gtk::Main::run(Gtk::Window&) (in /usr/lib/libgtkmm-2.4.so.1.1.0) ==5254== by 0x442F99: main (gtkmmWindow.cpp:66) ==5254== Address 0xd1ad9e8 is 8 bytes inside a block of size 24 free'd ==5254== at 0x4C27FF2: operator delete(void*) (vg_replace_malloc.c:387) ==5254== by 0x5B584E8: sigc::signal_base::~signal_base() (in /usr/lib/libsigc-2.0.so.0.0.0) ==5254== by 0x443A45: HelloWorld::on_destr_clicked() (gtkmmWindow.cpp:50) ==5254== by 0x4442B4: sigc::bound_mem_functor0<void, HelloWorld>::operator()() const (in /home/fabio/research/software/bin/gui/gtkmmWindow.greenplanet) ==5254== by 0x4441DF: sigc::adaptor_functor<sigc::bound_mem_functor0<void, HelloWorld> >::operator()() const (adaptor_trait.h:251) ==5254== by 0x444096: sigc::internal::slot_call0<sigc::bound_mem_functor0<void, HelloWorld>, void>::call_it(sigc::internal::slot_rep*) (slot.h:103) ==5254== by 0x5938B07: Glib::SignalProxyNormal::slot0_void_callback(_GObject*, void*) (in /usr/lib/libglibmm-2.4.so.1.3.0) ==5254== by 0x78AF0A3: g_closure_invoke (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3000.0) ==5254== by 0x78C11F4: ??? (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3000.0) ==5254== by 0x78CA6B0: g_signal_emit_valist (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3000.0) ==5254== by 0x78CA851: g_signal_emit (in /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0.3000.0) ==5254== by 0x7040904: ??? (in /usr/lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0.2400.6)
Which version of glibmm is this? I think this bug should be a duplicate of bug 651942, which has been fixed in glibmm 2.32. When I run your test case in my Ubuntu 12.04 system with glibmm 2.32 there's no segfault, but a lot of these messages: (example:2947): glibmm-WARNING **: Dropped dispatcher message as the dispatcher no longer exists
> Which version of glibmm is this? Judging from the filenames in the valgrind output I assume that you have used glib 2.30, and then probably glibmm 2.30. This bug has been fixed in glibmm 2.32. This is duplicate of bug 651942. *** This bug has been marked as a duplicate of bug 651942 ***