Skip to content

src: Fix IBusAttrList leak when converting text - #2943

Merged
fujiwarat merged 1 commit into
ibus:mainfrom
sbstnk:fix-attr-list-leak
Aug 30, 2026
Merged

fujiwarat merged 1 commit into
ibus:mainfrom
sbstnk:fix-attr-list-leak

Conversation

@sbstnk

@sbstnk sbstnk commented Aug 27, 2026

Copy link
Copy Markdown

After 5bbe88a the attribute list set on the text was getting leaked when the list passed to ibus_attr_list_copy_format_to_*() had a length of 0. In that case the list is already non-floating before the copy function adds a ref and returns it. This then is passed to ibus_text_set_attributes() which calls g_object_ref_sink(). Since the list is not floating, this adds another ref that would not be added in the length > 0 case. This surplus ref is causing the list to be leaked.

To fix this leak we need to unref the list after calling ibus_text_set_attributes().

However in the length > 0 case the new list returned by ibus_attr_list_copy_format_to_*() is floating, so this would drop the refcount to 0. To avoid this we need to ensure that if the list is floating the floating ref is sunk before calling ibus_text_set_attributes(), so the call to g_object_ref_sink() in there adds a ref, such that we can safely unref this after the call to ibus_text_set_attributes().

This also keeps the guarantee that the list is not floating anymore after converting text to not regress the issue fixed by 5bbe88a.

Fixes: 5bbe88a1
Closes: #2941

Comment thread src/ibusinputcontext.c Resolved
After 5bbe88a the attribute list set on the text was getting leaked
when the list passed to `ibus_attr_list_copy_format_to_*()` had a length
of 0. In that case the list is already non-floating before the copy
function adds a ref and returns it. This then is passed to
`ibus_text_set_attributes()` which calls `g_object_ref_sink()`. Since
the list is not floating, this adds another ref that would not be added
in the length > 0 case. This surplus ref is causing the list to be
leaked.

To fix this leak we need to unref the list after calling
`ibus_text_set_attributes()`.

However in the length > 0 case the new list returned by
`ibus_attr_list_copy_format_to_*()` is floating, so this would drop the
refcount to 0. To avoid this we need to ensure that if the list is floating the
floating ref is sunk before calling `ibus_text_set_attributes()`, so the
call to `g_object_ref_sink()` in there adds a ref, such that we can
safely unref this after the call to `ibus_text_set_attributes()`.

This also keeps the guarantee that the list is not floating anymore
after converting text to not regress the issue fixed by 5bbe88a.

Fixes: ibus@5bbe88a1
Closes: ibus#2941
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

IBusAttrList leaks in gnome-shell

2 participants