Skip to content

IBusAttrList leaks in gnome-shell #2941

Closed

Description

@sbstnk

Distribution and Version

Fedora 45

Desktop Environment and Version

GNOME 51.beta

Session Type

Wayland

Application and Version

gnome-shell 51.beta

IBus version

1.5.35~beta2

Issue Description

When running gnome-shell under valgrind I noticed a leak originating from ibus:

==1143602== 912 (384 direct, 528 indirect) bytes in 6 blocks are definitely lost in loss record 18,836 of 19,527
==1143602==    at 0x4F24EF7: g_type_create_instance (gtype.c:1877)
==1143602==    by 0x4F09277: g_object_constructor (gobject.c:3045)
==1143602==    by 0x4F09831: g_object_new_with_custom_constructor (gobject.c:2591)
==1143602==    by 0x4F0AE0B: g_object_new_internal (gobject.c:2669)
==1143602==    by 0x4F0AE0B: g_object_new_with_properties (gobject.c:2833)
==1143602==    by 0x4F0BD48: g_object_new (gobject.c:2481)
==1143602==    by 0x2E5E5DB9: ibus_serializable_deserialize_object (ibusserializable.c:307)
==1143602==    by 0x2E5E5F3C: ibus_text_deserialize (ibustext.c:121)
==1143602==    by 0x2E5E5DCB: ibus_serializable_deserialize_object (ibusserializable.c:309)
==1143602==    by 0x2E5D2FBB: ibus_input_context_g_signal (ibusinputcontext.c:639)
==1143602==    by 0x4F01EB7: g_closure_invoke (gclosure.c:916)
==1143602==    by 0x4F17223: signal_emit_unlocked_R.isra.0 (gsignal.c:3969)
==1143602==    by 0x4F1872A: signal_emit_valist_unlocked (gsignal.c:3561)

Looking at the trace, the leaked object is a IBusAttrList.

When going through the code to find potential sources of the leak, one thing I noticed was that in ibus_input_context_convert_text() there can be duplicate ref in case of ibus_attr_list_copy_format_to_rgba() or ibus_attr_list_copy_format_to_hint() hitting the attr_list->attributes->len == 0 code path. Then both the ibus_attr_list_copy_format_to_*() function and ibus_text_set_attributes() will add a ref. Those are probably the cases where the leaks come from.

In the other case, because the the new list is created with a floating ref and ibus_text_set_attributes() will sink it, this will result in only one ref and no leak.

(I have not confirmed yet if that's actually the source of the leaks)

Steps to Reproduce

1. Run `dbus-run-session valgrind --leak-check=full --show-leak-kinds=definite gnome-shell --wayland --devkit`
2. Close the devkit window again

Alternatively follow https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/main/docs/building-and-running.md?ref_type=heads#running-under-valgrind-with-a-full-session to run a full session under valgrind

Can you reproduce your problem when you restart ibus-daemon? (yes / no)

(not applicable)

Do you see any errors when you run ibus-daemon with the verbose option?

No response

Can you reproduce your problem with a new user account instead of the

current your account? (yes / no)

yes

Add any other context about the problem here.

I don't remember seeing this problem when I last ran valgrind on Fedora 44, i.e. ibus-1.5.34, so this is probably a somewhat recent issue.

All that is needed on the shell side for this leak to occur is:

  1. this._ibus = IBus.Bus.new_async()
  2. this._ibus.create_input_context_async()

The issue still occurs with all other ibus code in gnome-shell commented out.

Activity

  1. sbstnk commented on Aug 27, 2026

    @sbstnk
    Author

    Bisection points to 5bbe88a, which confirms my initial assumption.

    I think this leak can be avoided by doing something like this to turn only the floating ref from the new attr list into a proper ref while leaving the len == 0 case untouched and then dropping the the ref after the text has added its own:

    diff --git a/src/ibusinputcontext.c b/src/ibusinputcontext.c
    index bdfd166d..797be9eb 100644
    --- a/src/ibusinputcontext.c
    +++ b/src/ibusinputcontext.c
    @@ -569,8 +569,11 @@ ibus_input_context_convert_text (IBusInputContext *context,
                            text->text, error->message);
                 g_error_free (error);
             }
    -        if (new_attrs)
    +        if (new_attrs) {
    +            g_object_take_ref (new_attrs);
                 ibus_text_set_attributes (text, new_attrs);
    +            g_object_unref (new_attrs);
    +        }
             break;
         case IBUS_PREEDIT_FORMAT_HINT:
             new_attrs = ibus_attr_list_copy_format_to_hint (text->attrs, &error);
    @@ -579,8 +582,11 @@ ibus_input_context_convert_text (IBusInputContext *context,
                            text->text, error->message);
                 g_error_free (error);
             }
    -        if (new_attrs)
    +        if (new_attrs) {
    +            g_object_take_ref (new_attrs);
                 ibus_text_set_attributes (text, new_attrs);
    +            g_object_unref (new_attrs);
    +        }
             break;
         default:
             g_assert_not_reached ();

    The same change would be needed in ibus_panel_convert_text as well.

  2. added theissue type on Aug 30, 2026
  3. added this to the 1.5.35 milestone on Aug 30, 2026
  4. changed the title [-]IBusAttrList leaks[/-] [+]IBusAttrList leaks in gnome-shell[/+] on Aug 31, 2026
  5. fujiwarat commented on Sep 3, 2026

    @fujiwarat
    Member

    Now ibus-1.5.35~beta2-2.fc45 is available.
    I update a test case for this issue.
    f24d13e

  6. added 3 commits that reference this issue on Sep 4, 2026
    04520d0
    d437891
    d60f162
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions