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 693400 - gtkcellrenderertext: Sink floating entry before using as signal argument
gtkcellrenderertext: Sink floating entry before using as signal argument
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2013-02-08 07:27 UTC by Simon Feltman
Modified: 2017-10-14 20:25 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
gtkcellrenderertext: Sink floating entry before using as signal argument (1.77 KB, patch)
2013-02-08 07:28 UTC, Simon Feltman
reviewed Details | Review
gtkcellrenderertext: Sink floating entry before using as signal argument (1.62 KB, patch)
2013-02-11 05:05 UTC, Simon Feltman
committed Details | Review
Fixes bad placement of g_clear_object (1.05 KB, patch)
2015-06-12 01:27 UTC, Michael Webster
reviewed Details | Review

Description Simon Feltman 2013-02-08 07:27:54 UTC
The GtkCellRendererText creates a GtkEntry and sends out the "editing-started" signal before the entry is ever sunk. This creates problems with language bindings because bindings always sink floating objects. By the time the signal closure is complete, the entry will have been destroyed because the bindings object wrapper sunk and assumed ownership of the floating reference. This originally started as a pygobject bug and was fixed by always adding an additional ref during object marshaling, this however created a reference leak. See also: bug 661359 and bug 675726
Comment 1 Simon Feltman 2013-02-08 07:28:26 UTC
Created attachment 235485 [details] [review]
gtkcellrenderertext: Sink floating entry before using as signal argument

Sink the GtkEntry assigned to the private structure of GtkCellRendererText
before signals contianing it as an argument are sent out. This keeps
language bindings from sinking the reference and then destroying the entry
when the signal closure is finished.
Comment 2 Matthias Clasen 2013-02-11 02:59:27 UTC
Review of attachment 235485 [details] [review]:

Other than that, looks good to me. The reference handling in the cell editing code was always a bit shaky.

::: gtk/gtkcellrenderertext.c
@@ +754,3 @@
+  if (priv->entry)
+    g_object_unref (priv->entry);
+

g_clear_object

@@ +1923,3 @@
+      g_object_unref (priv->entry);
+      priv->entry = NULL;
+    }

here too: g_clear_object

@@ +2055,3 @@
 
+  if (priv->entry)
+    g_object_unref (priv->entry);

I think this is not necessary - the api contract requires that editing_done is called before start_editing can be called again.
Comment 3 Simon Feltman 2013-02-11 05:05:00 UTC
Created attachment 235673 [details] [review]
gtkcellrenderertext: Sink floating entry before using as signal argument

Fixed up based on review feeback.
Comment 4 Matthias Clasen 2013-02-11 23:58:23 UTC
Review of attachment 235673 [details] [review]:

ok
Comment 5 Simon Feltman 2013-02-12 02:04:33 UTC
Attachment 235673 [details] pushed as 283c974 - gtkcellrenderertext: Sink floating entry before using as signal argument
Comment 6 Michael Webster 2015-06-12 01:26:19 UTC
Hi, the g_clear_object in the second chunk of this patch seems to be in the wrong place.

It's causing destruction of the GtkCellEditable, but we immediately proceed to try to disconnect its signal handlers, as well as get its text and path to pass on to the 'edited' signal handlers for the cell renderer.

I'm experiencing this in 3.14 (though it appears that it would afflict anything newer as well)

Placing it after the signal emission resolves the issues.

Attaching a fix that does just that.

Thanks!
Comment 7 Michael Webster 2015-06-12 01:27:30 UTC
Created attachment 305108 [details] [review]
Fixes bad placement of g_clear_object
Comment 8 Michael Webster 2015-06-12 12:26:27 UTC
Trace just to document the crash... 

(nemo:2775): GLib-GObject-WARNING **: instance with invalid (NULL) class pointer

(nemo:2775): GLib-GObject-CRITICAL **: g_signal_handler_disconnect: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(nemo:2775): GLib-GObject-WARNING **: instance with invalid (NULL) class pointer

(nemo:2775): GLib-GObject-CRITICAL **: g_signal_handler_disconnect: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed

(nemo:2775): GLib-GObject-CRITICAL **: g_object_get: assertion 'G_IS_OBJECT (object)' failed

(nemo:2775): GLib-GObject-CRITICAL **: g_object_get_data: assertion 'G_IS_OBJECT (object)' failed

(nemo:2775): Gtk-CRITICAL **: gtk_entry_get_text: assertion 'GTK_IS_ENTRY (entry)' failed

Program received signal SIGSEGV, Segmentation fault.
cell_renderer_edited (cell=<optimized out>, path_str=0x0, new_text=0x0, view=0xcee360) at nemo-list-view.c:1423
1423		if (new_text[0] == '\0') {
(gdb) bt
  • #0 cell_renderer_edited
    at nemo-list-view.c line 1423
  • #1 g_closure_invoke
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #2 ??
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #3 g_signal_emit_valist
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #4 g_signal_emit
    from /usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0
  • #5 gtk_cell_renderer_text_editing_done
    at /tmp/buildd/gtk+3.0-3.14.5+3+betsy/./gtk/gtkcellrenderertext.c line 1975
  • #6 popdown_timeout
    at /tmp/buildd/gtk+3.0-3.14.5+3+betsy/./gtk/gtkcellrenderertext.c line 1988
  • #7 gdk_threads_dispatch
    at /tmp/buildd/gtk+3.0-3.14.5+3+betsy/./gdk/gdk.c line 654
  • #8 ??
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #9 g_main_context_dispatch
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #10 ??
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #11 g_main_context_iteration
    from /lib/x86_64-linux-gnu/libglib-2.0.so.0
  • #12 g_application_run
    from /usr/lib/x86_64-linux-gnu/libgio-2.0.so.0
  • #13 main
    at nemo-main.c line 101


If I run with G_DEBUG=fatal-warnings, I can see the warnings and assertions leading up to it are from gtk_cell_renderer_text_editing_done() screaming about the unrefed GtkCellEditable.
Comment 9 Daniel Boles 2017-10-14 20:25:28 UTC
Review of attachment 305108 [details] [review]:

This changes the sense of the function: it now fails to g_clear_object(&priv->entry) if editing was cancelled. That's probably not a good thing.

Looking at what other CellRenderer implementations do in this method may be instructive; I didn't look far yet.

Anyway, if this still causes problems, it should get a new bug report. (or, at the very least, reopen the one you're piling on to, so that it stands a chance of being found)