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 583481 - Gtk::FileFilter not copied properly when passed as a local variable
Gtk::FileFilter not copied properly when passed as a local variable
Status: RESOLVED FIXED
Product: gtkmm
Classification: Bindings
Component: general
2.16.x
Other Linux
: Normal normal
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2009-05-21 17:46 UTC by Soo Wei Tan
Modified: 2010-12-23 21:47 UTC
See Also:
GNOME target: ---
GNOME version: 2.25/2.26


Attachments
Test case (2.53 KB, text/x-c++src)
2009-05-21 17:48 UTC, Soo Wei Tan
Details
Test case, modified for Gnome 3 (2.84 KB, text/plain)
2010-12-13 16:27 UTC, Kjell Ahlstedt
Details

Description Soo Wei Tan 2009-05-21 17:46:43 UTC
OS: Ubuntu 9.04

I'm trying to create some Gtk::FileFilters to be passed into a Gtk::FileChooserDialog. I have a helper function that creates the filters, but I get an null pointer when calling FileChooserDialog::get_filter() after FileChooserDialog::run().

I will attach the example application too.

Here is the trace from gdb:
soowei@williams:~/Development/temp/filechooserdialog$ gdb ./filechooserdialog 
GNU gdb 6.8-debian
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu"...
(gdb) run
Starting program: /home/soowei/Development/temp/filechooserdialog/filechooserdialog 
[Thread debugging using libthread_db enabled]
[New Thread 0xb6d18720 (LWP 30883)]
[New Thread 0xb659db90 (LWP 30886)]
[New Thread 0xb5affb90 (LWP 30887)]
[Thread 0xb5affb90 (LWP 30887) exited]

(filechooserdialog:30883): glibmm-WARNING **: Glib::wrap_create_new_wrapper: Attempted to create a 2nd C++ wrapper for a C instance whose C++ wrapper has been deleted.

(filechooserdialog:30883): glibmm-WARNING **: Failed to wrap object of type 'gtkmm__GtkFileFilter'. Hint: this error is commonly caused by failing to call a library init() function.

Program received signal SIGSEGV, Segmentation fault.

Thread 3067184928 (LWP 30883)

  • #0 Gtk::FileFilter::get_name
    at filefilter.cc line 203
  • #1 ExampleWindow::on_button_file_clicked
    at main.cc line 87
  • #2 sigc::bound_mem_functor0<void, ExampleWindow>::operator()
    at /usr/include/sigc++-2.0/sigc++/functors/mem_fun.h line 1787
  • #3 sigc::adaptor_functor<sigc::bound_mem_functor0<void, ExampleWindow> >::operator()
    at /usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h line 251
  • #4 sigc::internal::slot_call0<sigc::bound_mem_functor0<void, ExampleWindow>, void>::call_it
    at /usr/include/sigc++-2.0/sigc++/functors/slot.h line 103
  • #5 Glib::SignalProxyNormal::slot0_void_callback
    from /usr/lib/libglibmm-2.4.so.1
  • #6 IA__g_cclosure_marshal_VOID__VOID
    at /build/buildd/glib2.0-2.20.1/gobject/gmarshal.c line 77
  • #7 IA__g_closure_invoke
    at /build/buildd/glib2.0-2.20.1/gobject/gclosure.c line 767
  • #8 signal_emit_unlocked_R
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3317
  • #9 IA__g_signal_emit_valist
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 2980
  • #10 IA__g_signal_emit
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3037
  • #11 IA__gtk_button_clicked
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkbutton.c line 1106
  • #12 gtk_real_button_released
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkbutton.c line 1702
  • #13 Gtk::Button_Class::released_callback
    at button.cc line 245
  • #14 IA__g_cclosure_marshal_VOID__VOID
    at /build/buildd/glib2.0-2.20.1/gobject/gmarshal.c line 77
  • #15 g_type_class_meta_marshal
    at /build/buildd/glib2.0-2.20.1/gobject/gclosure.c line 878
  • #16 IA__g_closure_invoke
    at /build/buildd/glib2.0-2.20.1/gobject/gclosure.c line 767
  • #17 signal_emit_unlocked_R
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3177
  • #18 IA__g_signal_emit_valist
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 2980
  • #19 IA__g_signal_emit
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3037
  • #20 IA__gtk_button_released
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkbutton.c line 1098
  • #21 gtk_button_button_release
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkbutton.c line 1594
  • #22 Gtk::Widget_Class::button_release_event_callback
    at widget.cc line 4676
  • #23 _gtk_marshal_BOOLEAN__BOXED
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkmarshalers.c line 84
  • #24 g_type_class_meta_marshal
  • #25 IA__g_closure_invoke
    at /build/buildd/glib2.0-2.20.1/gobject/gclosure.c line 767
  • #26 signal_emit_unlocked_R
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3285
  • #27 IA__g_signal_emit_valist
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 2990
  • #28 IA__g_signal_emit
    at /build/buildd/glib2.0-2.20.1/gobject/gsignal.c line 3037
  • #29 gtk_widget_event_internal
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkwidget.c line 4761
  • #30 IA__gtk_propagate_event
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkmain.c line 2396
  • #31 IA__gtk_main_do_event
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkmain.c line 1601
  • #32 gdk_event_dispatch
  • #33 IA__g_main_context_dispatch
    at /build/buildd/glib2.0-2.20.1/glib/gmain.c line 1814
  • #34 g_main_context_iterate
    at /build/buildd/glib2.0-2.20.1/glib/gmain.c line 2448
  • #35 IA__g_main_loop_run
    at /build/buildd/glib2.0-2.20.1/glib/gmain.c line 2656
  • #36 IA__gtk_main
    at /build/buildd/gtk+2.0-2.16.1/gtk/gtkmain.c line 1205
  • #37 Gtk::Main::run_impl
    at main.cc line 536
  • #38 Gtk::Main::run
    at main.cc line 490
  • #39 main
    at main.cc line 96

Comment 1 Soo Wei Tan 2009-05-21 17:48:23 UTC
Created attachment 135132 [details]
Test case

To reproduce:
Compile and run application. 
Click "Choose File".
Either select a file and click Save As, or just Cancel out of the dialog.
Application crashes.
Comment 2 Murray Cumming 2010-05-04 11:09:30 UTC
Sorry for not noticing this until now. This reply is terribly late. Anyway:

Of course, you should check for null pointers before dereferencing them. But yes, the point is that the Gtk::FileFilter* should not be null.

The backtrace at the first warning (break g_log) isn't very interesting:

  • #1 wrap_create_new_wrapper
    at wrap.cc line 102
  • #2 Glib::wrap_auto
    at wrap.cc line 187
  • #3 Glib::wrap
    at filefilter.cc line 96
  • #4 Gtk::FileChooser::get_filter
    at filechooser.cc line 608
  • #5 ExampleWindow::on_button_file_clicked()

Valgrind doesn't give any hints either. I did notice that we are refing the result of get_filter(), which is not appropriate because GtkFilter derives from GtkObject, not GObject, but fixing that does not seem to help. 

I guess that GTK+ is doing something strange with the underlying C pointer. It needs more investigation.
Comment 3 Kjell Ahlstedt 2010-09-22 07:35:07 UTC
What about the following explanation?

The C++ wrappers, Gtk::FileFilter, are local variables in AddFilters in the
test case program. At the end of AddFilters, the Gtk::FileFilter objects are
destroyed, but the wrapped GtkFileFilter objects are not, since pointers to
them have been stored in the GtkFileChooserDialog object, and their ref counts
have been increased accordingly.

Gtk::FileFilter's destructor, or rather Gtk::Object::~Object, stores in the
GObject object, a Glib::quark_cpp_wrapper_deleted_. Then the function
Glib::wrap, called by Gtk::FileChooser::get_filter, refuses to create a new
C++ wrapper for the GtkFileFilter object, returned by
gtk_file_chooser_get_filter.

I moved the code in the test case program from AddFilters to
ExampleWindow::on_button_file_clicked. Then the Gtk::FileFilter objects still
exist when dialog.get_filter() is called, dialog.get_filter() returns a
valid pointer, and there is no segmentation fault.
I've used gtkmm version 2.20.3 in Ubuntu 10.04.
Comment 4 Kjell Ahlstedt 2010-12-13 16:27:25 UTC
Created attachment 176342 [details]
Test case, modified for Gnome 3

On 2010-09-27, just a few days after I filed comment 3, Gtk::FileFilter and
Gtk::FileChooser were modifed in the Gnome 3 master branch in the Git
repository. Now FileFilter is accessed via Glib::RefPtr<Gtk::FileFilter>.
That modification fixes this bug, as far as I can see. I've attached a
modified version of the test case in comment 1. It works just fine, no segfault
or other problem. But it can be compiled only with the Gnome 3 version of
gtkmm.
Comment 5 Murray Cumming 2010-12-23 21:47:49 UTC
Yes, let's just consider this fixed in gtkmm 3. Thanks.