Skip to content

Commit 5bbe88a

Browse files
cthbleachbitfujiwarat
authored andcommitted
src: make an IBusText own an updated IBusAttrList reference
For all usages of IBusAttrList, the list is an owned reference within a IBusText struct. `ibus_panel_convert_text()` and `ibus_input_context_convert_text()` violate the invarient by assigning a **floating** IBusAttrList reference to anIBusText without sinking it. When GJS attempts to create a JS representation of an existing GObject, it unconditionally sinks the incoming reference.[1] For a non-floating reference this up-refs the object. For this floating IBusAttrLit, `g_object_ref_sink` converts it to a strong reference in-place leaving ref-count at 1. At this point the `IBusAttrList` is referenced by both the enclosing `IBusText` and the newly created GJS wrapper. When one of them is ref-downed the object is recycled, leaving the other reference dangling. To fix this we just need to maintain the list as a non-floating ref. We already have a `ibus_text_set_attributes()` that does the intended ref sinking, so just use that instead of manually assigning pointers. [1]: https://gitlab.gnome.org/GNOME/gjs/-/blob/db450465ab0161e131a92992c2509507aa6152aa/gi/object.cpp#L3597 Closes: #2889
1 parent 526e509 commit 5bbe88a

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

‎src/ibusinputcontext.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -569,10 +569,8 @@ ibus_input_context_convert_text (IBusInputContext *context,
569569
text->text, error->message);
570570
g_error_free (error);
571571
}
572-
if (new_attrs) {
573-
g_object_unref (text->attrs);
574-
text->attrs = new_attrs;
575-
}
572+
if (new_attrs)
573+
ibus_text_set_attributes (text, new_attrs);
576574
break;
577575
case IBUS_PREEDIT_FORMAT_HINT:
578576
new_attrs = ibus_attr_list_copy_format_to_hint (text->attrs, &error);
@@ -581,10 +579,8 @@ ibus_input_context_convert_text (IBusInputContext *context,
581579
text->text, error->message);
582580
g_error_free (error);
583581
}
584-
if (new_attrs) {
585-
g_object_unref (text->attrs);
586-
text->attrs = new_attrs;
587-
}
582+
if (new_attrs)
583+
ibus_text_set_attributes (text, new_attrs);
588584
break;
589585
default:
590586
g_assert_not_reached ();

‎src/ibuspanelservice.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,10 +1203,8 @@ ibus_panel_convert_text (IBusPanelService *panel,
12031203
text->text, error->message);
12041204
g_error_free (error);
12051205
}
1206-
if (new_attrs) {
1207-
g_object_unref (text->attrs);
1208-
text->attrs = new_attrs;
1209-
}
1206+
if (new_attrs)
1207+
ibus_text_set_attributes (text, new_attrs);
12101208
break;
12111209
case IBUS_PREEDIT_FORMAT_HINT:
12121210
new_attrs = ibus_attr_list_copy_format_to_hint (text->attrs, &error);
@@ -1215,10 +1213,8 @@ ibus_panel_convert_text (IBusPanelService *panel,
12151213
text->text, error->message);
12161214
g_error_free (error);
12171215
}
1218-
if (new_attrs) {
1219-
g_object_unref (text->attrs);
1220-
text->attrs = new_attrs;
1221-
}
1216+
if (new_attrs)
1217+
ibus_text_set_attributes (text, new_attrs);
12221218
break;
12231219
default:
12241220
g_assert_not_reached ();

0 commit comments

Comments
 (0)