After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 350734 - segfault in RadioAction constructor
segfault in RadioAction constructor
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.9.x
Other All
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2006-08-10 12:56 UTC by Jonathon Jongsma
Modified: 2007-04-18 16:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case that doesn't segfault (703 bytes, text/plain)
2006-08-10 14:04 UTC, Paul Davis
  Details
Proposed patch (1.94 KB, patch)
2007-04-12 15:43 UTC, Armin Burgmeier
committed Details | Review

Description Jonathon Jongsma 2006-08-10 12:56:19 UTC
When trying to inherit from RadioAction, the constructor causes a segfault.  This occurs at least in 2.6 and later.  Example program:


#include <glibmm/refptr.h>
#include <gtkmm/main.h>
#include <gtkmm/radioaction.h>
#include <gtkmm/stock.h>


namespace
{

 class Radio_action : public Gtk::RadioAction
 {
 public:

   Radio_action (Group& group)
     : Gtk::RadioAction (group, "test", Gtk::StockID (), "", "")
   { }

   static  Glib::RefPtr <Radio_action>
   create (Group& group)
   {
     return Glib::RefPtr <Radio_action> (new Radio_action (group));
   }
 };

}


int
main (int argc, char** argv)
{
 Gtk::Main  main (argc, argv);

 Radio_action::Group  test_group;

#if 1
 // This segfaults.
 Radio_action::create (test_group);
#else
 Gtk::RadioAction::create (test_group, "test");
#endif

 return 0;
}


stack trace:
(gdb) run
Starting program: /home/doug/testprg/a.out
[Thread debugging using libthread_db enabled]
[New Thread 46912496377392 (LWP 16809)]

Program received signal SIGSEGV, Segmentation fault.

Thread 46912496377392 (LWP 16809)

  • #0 g_type_check_instance_is_a
    from /usr/lib64/libgobject-2.0.so.0
  • #1 gtk_radio_action_get_group
    from /usr/lib64/libgtk-x11-2.0.so.0
  • #2 Gtk::RadioAction::get_group
    from /usr/lib64/libgtkmm-2.4.so.1
  • #3 Gtk::RadioAction::set_group
    from /usr/lib64/libgtkmm-2.4.so.1
  • #4 Gtk::RadioAction::RadioAction\$base
    from /usr/lib64/libgtkmm-2.4.so.1
  • #5 Radio_action
    at testprg.cc line 15
  • #6 (anonymous namespace)::Radio_action::create
    at testprg.cc line 21
  • #7 main
    at testprg.cc line 37

Comment 1 Paul Davis 2006-08-10 14:04:45 UTC
Created attachment 70644 [details]
Test case that doesn't segfault

Adding Glib::ObjectBase(0) to the static initialization of the constructor prevents the segfault.
Comment 2 Jonathon Jongsma 2006-08-10 14:24:21 UTC
Interesting.  Clearly we don't want to have to actually do that manually in our derived classes though.  I don't have a lot of time in the next few days, but i'll try to dig into this a bit more at some point unless somebody comes up with something better before I get to it.
Comment 3 Armin Burgmeier 2007-04-12 15:43:08 UTC
Created attachment 86241 [details] [review]
Proposed patch

The problem lies within the changed signal of the radio action, which is eventually emitted in the set_group() call. The code generated for the signal contains a line that should invoke the C++ default signal handler and that looks roughly like this:

obj->on_changed(Glib::wrap(p1));

where p1 is a GtkRadioAction*, in this case the same object as the object obj wraps. Glib::wrap() creates a temporary Glib::RefPtr<Gtk::ActionGroup> that decreases the reference count of p1 eventually without ever having refed it. The patch now calls Glib::wrap(p1, true) to take an additional reference. It also moves the conversion macro to radioaction.hg because other places might need a conversion without an own reference (however, currently this is the only place where such a conversion is ever required).

I wonder whether there are similar situations with other signals in gtkmm.
Comment 4 Murray Cumming 2007-04-18 16:09:58 UTC
Excellent. Please apply to svn trunk.

You might remove the conversion from the general .m4 conversion file, to see if any more signals need the same attention.
Comment 5 Armin Burgmeier 2007-04-18 16:17:38 UTC
This is what I already did, but I thought of problems with other types.