LeakSanitizer: detected memory leaks in message_bus_get_singleton
In all my fwupd unit tests that use DBUS I get an Asan error saying that I'm leaking the message_bus_get_singleton. In the GLib tests this is seemingly prevented using the internal symbol _g_bus_forget_singleton()
to free it manually:
==73977== HEAP SUMMARY:
==73977== in use at exit: 153,854 bytes in 1,792 blocks
==73977== total heap usage: 8,937 allocs, 7,145 frees, 650,178 bytes allocated
==73977==
==73977== 8 bytes in 1 blocks are definitely lost in loss record 68 of 1,378
==73977== at 0x483EAE9: calloc (vg_replace_malloc.c:760)
==73977== by 0x4B3D790: g_malloc0 (gmem.c:136)
==73977== by 0x49CCBA9: UnknownInlinedFun (gdbusproxy.c:101)
==73977== by 0x49CCBA9: async_initable_init_first (gdbusproxy.c:1703)
==73977== by 0x49CCEC3: get_connection_cb (gdbusproxy.c:1785)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x496512A: UnknownInlinedFun (gtask.c:1289)
==73977== by 0x496512A: g_task_return (gtask.c:1245)
==73977== by 0x49C34E1: bus_get_async_initable_cb (gdbusconnection.c:7395)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x4964F6C: complete_in_idle_cb (gtask.c:1233)
==73977== by 0x4B3404A: g_idle_dispatch (gmain.c:5836)
==73977== by 0x4B34F9E: UnknownInlinedFun (gmain.c:3325)
==73977== by 0x4B34F9E: g_main_context_dispatch (gmain.c:4043)
==73977== by 0x4B88527: g_main_context_iterate.constprop.0 (gmain.c:4119)
==73977==
==73977== 8 bytes in 1 blocks are definitely lost in loss record 69 of 1,378
==73977== at 0x483EAE9: calloc (vg_replace_malloc.c:760)
==73977== by 0x4B3D790: g_malloc0 (gmem.c:136)
==73977== by 0x49CCB39: UnknownInlinedFun (gdbusproxy.c:101)
==73977== by 0x49CCB39: async_initable_init_first (gdbusproxy.c:1719)
==73977== by 0x49CCEC3: get_connection_cb (gdbusproxy.c:1785)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x496512A: UnknownInlinedFun (gtask.c:1289)
==73977== by 0x496512A: g_task_return (gtask.c:1245)
==73977== by 0x49C34E1: bus_get_async_initable_cb (gdbusconnection.c:7395)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x4964F6C: complete_in_idle_cb (gtask.c:1233)
==73977== by 0x4B3404A: g_idle_dispatch (gmain.c:5836)
==73977== by 0x4B34F9E: UnknownInlinedFun (gmain.c:3325)
==73977== by 0x4B34F9E: g_main_context_dispatch (gmain.c:4043)
==73977== by 0x4B88527: g_main_context_iterate.constprop.0 (gmain.c:4119)
==73977==
==73977== 8 bytes in 1 blocks are definitely lost in loss record 70 of 1,378
==73977== at 0x483EAE9: calloc (vg_replace_malloc.c:760)
==73977== by 0x4B3D790: g_malloc0 (gmem.c:136)
==73977== by 0x49CCC29: UnknownInlinedFun (gdbusproxy.c:101)
==73977== by 0x49CCC29: async_initable_init_first (gdbusproxy.c:1735)
==73977== by 0x49CCEC3: get_connection_cb (gdbusproxy.c:1785)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x496512A: UnknownInlinedFun (gtask.c:1289)
==73977== by 0x496512A: g_task_return (gtask.c:1245)
==73977== by 0x49C34E1: bus_get_async_initable_cb (gdbusconnection.c:7395)
==73977== by 0x4964F29: g_task_return_now (gtask.c:1219)
==73977== by 0x4964F6C: complete_in_idle_cb (gtask.c:1233)
==73977== by 0x4B3404A: g_idle_dispatch (gmain.c:5836)
==73977== by 0x4B34F9E: UnknownInlinedFun (gmain.c:3325)
==73977== by 0x4B34F9E: g_main_context_dispatch (gmain.c:4043)
==73977== by 0x4B88527: g_main_context_iterate.constprop.0 (gmain.c:4119)
==73977==
==73977== LEAK SUMMARY:
==73977== definitely lost: 24 bytes in 3 blocks
Should GLib export _g_bus_forget_singleton() or should it do some atexit() magic? The simple reproducer I have is either https://github.com/fwupd/fwupd/blob/master/libfwupd/fwupd-thread-test.c or https://github.com/fwupd/fwupd/blob/master/libfwupd/fwupd-context-test.c
Happy to write a patch if reqd.