Skip to content

st-label: Unset clutter text instance on disposal

Marco Trevisan requested to merge 3v1n0/gnome-shell:st-label-dispose into master

Crashes on st-label still continues to be around, while I've planned to do to some further changes to gjs to prevent this, also st-label should just warn when we use disposed elements, instead of causing crashes.

One crash I got and tracked was like this:

#1 0x00007f3abc9a1bc8 in st_label_set_text (label=0x555b3f768d10, text=0x555b5369d360 "...")
    at ../../gnome-shell/src/st/st-label.c:331
331 ctext = CLUTTER_TEXT (priv->label);
(gdb) list
326
327 g_return_if_fail (ST_IS_LABEL (label));
328 g_return_if_fail (text != NULL);
329
330 priv = label->priv;
331 ctext = CLUTTER_TEXT (priv->label);
332
333 if (clutter_text_get_editable (ctext) ||
334 g_strcmp0 (clutter_text_get_text (ctext), text) != 0)
335 {
(gdb) print label
$1 = (StLabel *) 0x555b3f768d10
(gdb) print *label
$2 = {parent_instance = {parent_instance = {parent_instance = {g_type_instance = {g_class = 0x555b3e5ea510},
        ref_count = 1, qdata = 0x555b3f759800}, flags = 0, private_flags = 0, priv = 0x555b3f7689f0}},
  priv = 0x555b3f7688b0}
(gdb) print *label->priv
$3 = {label = 0x555b3f712210, text_shadow_pipeline = 0x0, shadow_width = -1, shadow_height = -1}
(gdb) print *label->priv->label
$4 = {parent_instance = {g_type_instance = {g_class = 0x7f3abdf80be0
     <wrapped_gobj_dispose_notify(gpointer, GObject*)>}, ref_count = 1102656128, qdata = 0x30}, flags = 113,
  private_flags = 0, priv = 0x68733b6572616873}

The js trace:

(gnome-shell:6754): Gjs-CRITICAL **: 12:22:49.131: Object St.Label (0x555b3f768d10), has been already deallocated - impossible to access to it. This might be caused by the fact that the object has been destroyed from C code using something such as destroy(), dispose(), or remove() vfuncs
== Stack trace for context 0x55950f5194c0 ==
#0 0x55950f8dd500 i   /home/marco/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/extension.js:97 (0x7f1e0fa866f8 @ 50)
#1 0x7fffe152ef20 I   resource:///org/gnome/gjs/modules/_legacy.js:82 (0x7f1e5c5b5e68 @ 71)
#2 0x55950f8dd480 i   /home/marco/.local/share/gnome-shell/extensions/clipboard-indicator@tudmotu.com/extension.js:567 (0x7f1e0fab7098 @ 20)

The instance is owned by the actor (being its child), and thus when the disposal happens for the parent the text is disposed too, thus it's just safer to nullify its reference so that we won't try to access to invalid objects later, and this might be the case since the JS objects could be kept around until they aren't finalized.

https://bugzilla.gnome.org/show_bug.cgi?id=788931

Merge request reports