Skip to content
  • Anderson Lizardo's avatar
    gdbus: Fix incorrect DBusConnection reference counting · 0b2e4b1d
    Anderson Lizardo authored
    Commit abfc2b0dd5c3e33abfdf1a815b16d492c1751c06 attempted to fix a crash
    related to improper reference counting, but the main issue was that the
    reference was taken only during the function call (which is usually
    unnecessary for single thread), but still passed a pointer to
    DBusConnection to a function that is called by the mainloop. This left a
    window where the DBusConnection can be destroyed.
    
    Fixes this crash on unit/test-gdbus-client:
    
    ==32642== Invalid read of size 4
    ==32642==    at 0x690D0A6: dbus_connection_ref (in
    /lib/i386-linux-gnu/libdbus-1.so.3.7.6)
    ==32642==    by 0x804CEDB: message_dispatch (mainloop.c:73)
    ==32642==    by 0x684580E: g_timeout_dispatch (gmain.c:4450)
    ==32642==    by 0x6844A75: g_main_context_dispatch (gmain.c:3065)
    ==32642==    by 0x6844E14: g_main_context_iterate.isra.23 (gmain.c:3712)
    ==32642==    by 0x68452FA: g_main_loop_run (gmain.c:3906)
    ==32642==    by 0x804C7D3: client_connect_disconnect
    (test-gdbus-client.c:188)
    ==32642==    by 0x6868DB2: g_test_run_suite_internal (gtestutils.c:2067)
    ==32642==    by 0x6868F8D: g_test_run_suite_internal (gtestutils.c:2138)
    ==32642==    by 0x6869320: g_test_run_suite (gtestutils.c:2189)
    ==32642==    by 0x686936B: g_test_run (gtestutils.c:1508)
    ==32642==    by 0x696D4D2: (below main) (libc-start.c:226)
    ==32642==  Address 0x709c6e4 is 140 bytes inside a block of size 144
    free'd
    ==32642==    at 0x67E806C: free (in
    /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
    ==32642==    by 0x692D62E: dbus_free (in
    /lib/i386-linux-gnu/libdbus-1.so.3.7.6)
    ==32642==    by 0x690E1C2: ??? (in
    /lib/i386-linux-gnu/libdbus-1.so.3.7.6)
    ==32642==    by 0x804AAEC: destroy_context (test-gdbus-client.c:104)
    ==32642==    by 0x6868DB2: g_test_run_suite_internal (gtestutils.c:2067)
    ==32642==    by 0x6868F8D: g_test_run_suite_internal (gtestutils.c:2138)
    ==32642==    by 0x6869320: g_test_run_suite (gtestutils.c:2189)
    ==32642==    by 0x686936B: g_test_run (gtestutils.c:1508)
    ==32642==    by 0x696D4D2: (below main) (libc-start.c:226)
    0b2e4b1d