dbus-gmain.c mem leak

David Zeuthen david at fubar.dk
Mon Apr 18 17:27:22 PDT 2005


Hey,

Attached is a test case (I've got the problem for real too in hal) that
demonstrates a memory leak in the dbus-glib code. You need a session bus
for this work and also HEAD to avoid memory leaks in the message bus
daemon that were fixed post 0.32. Compile with

        [davidz at daxter dbus]$ gcc -g -o dbus-test-case dbus-test-case.c -DDBUS_API_SUBJECT_TO_CHANGE `pkg-config --libs --cflags dbus-glib-1`
        [davidz at daxter dbus]$ ./dbus-test-case
        child pid is 21353
        parent pid is 21352
        parent now owns the 'org.example.TestService' name
        child unique name is ':1.31'
        
After a while, top gives me this

        21352 davidz    25   0  4032 2272  848 R 75.0  0.4   0:42.18 dbus-test-case
        21207 davidz    15   0 12684 1324 1156 S 15.7  0.3   4:33.24 dbus-daemon
        21353 davidz    16   0  2844  880  752 S  4.6  0.2   0:05.42 dbus-test-case
        
where it's obvious that the parent is leaking. If I remove these lines
in parent_filter_func()

		dbus_error_init (&error);
		sender_uid = dbus_bus_get_unix_user (connection, dbus_message_get_sender (message), &error);

there is no leak anymore. I can also get the child to leak; if I do a 

	GMainLoop *loop;

	if ((loop = g_main_loop_new (NULL, FALSE)) == NULL) {
		printf ("cannot create mainloop\n");
		goto out;
	}
	dbus_connection_setup_with_g_main (conn, NULL);

after having acquired the connection in child(). valgrind isn't really
all that helpful, in [1] is the output from running the program (without
the child leaking).

Anyone got a clue what's happening before I investigate further? 

Also, would it be useful to integrate this test into the dbus source
tree? If so, what is the best approach to integrate it?

Thanks,
David

[1] :

[davidz at daxter dbus]$ valgrind --show-reachable=yes --leak-check=full --tool=addrcheck ./dbus-test-case
==21407== Addrcheck, a fine-grained address checker for x86-linux.
==21407== Copyright (C) 2002-2005, and GNU GPL'd, by Julian Seward et al.
==21407== Using valgrind-2.4.0, a program supervision framework for x86-linux.
==21407== Copyright (C) 2000-2005, and GNU GPL'd, by Julian Seward et al.
==21407== For more details, rerun with: -v
==21407==
child pid is 21408
parent pid is 21407
parent now owns the 'org.example.TestService' name
child unique name is ':1.43'
==21407==
==21407== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==21407== malloc/free: in use at exit: 89141 bytes in 1273 blocks.
==21407== malloc/free: 14410 allocs, 13137 frees, 326776 bytes allocated.
==21407== For counts of detected errors, rerun with: -v
==21407== searching for pointers to 1273 not-freed blocks.
==21407== checked 216080 bytes.
==21407==
==21407== 88 bytes in 3 blocks are still reachable in loss record 1 of 6
==21407==    at 0x3414E222: malloc (vg_replace_malloc.c:130)
==21407==    by 0x3414EBE5: realloc (vg_replace_malloc.c:188)
==21407==    by 0xAD2ACE: g_realloc (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xAB479D: (within /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xAB4C66: g_ptr_array_add (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACEED1: g_main_context_check (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACF16C: (within /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACF6E2: g_main_loop_run (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0x8048BB7: parent (dbus-test-case.c:74)
==21407==    by 0x8048D3E: main (dbus-test-case.c:145)
==21407==
==21407==
==21407== 1186 bytes in 25 blocks are still reachable in loss record 2 of 6
==21407==    at 0x3414E222: malloc (vg_replace_malloc.c:130)
==21407==    by 0x341A3A70: dbus_malloc (dbus-memory.c:469)
==21407==    by 0x3419CC3C: _dbus_strdup (dbus-internals.c:313)
==21407==    by 0x34170F98: dbus_bus_get (dbus-bus.c:162)
==21407==    by 0x8048B06: parent (dbus-test-case.c:54)
==21407==    by 0x8048D3E: main (dbus-test-case.c:145)
==21407==
==21407==
==21407== 1508 bytes in 21 blocks are still reachable in loss record 3 of 6
==21407==    at 0x3414EB71: calloc (vg_replace_malloc.c:175)
==21407==    by 0x341A39B6: dbus_malloc0 (dbus-memory.c:519)
==21407==    by 0x341A3C2E: _dbus_mem_pool_new (dbus-mempool.c:141)
==21407==    by 0x3419D087: alloc_link (dbus-list.c:63)
==21407==    by 0x3419D1D3: _dbus_list_prepend (dbus-list.c:276)
==21407==    by 0x3419D20B: _dbus_list_append (dbus-list.c:252)
==21407==    by 0x3416C009: dbus_parse_address (dbus-address.c:353)
==21407==    by 0x341754C2: _dbus_connection_open_internal (dbus-connection.c:1587)
==21407==    by 0x34170E29: dbus_bus_get (dbus-bus.c:381)
==21407==    by 0x8048B06: parent (dbus-test-case.c:54)
==21407==    by 0x8048D3E: main (dbus-test-case.c:145)
==21407==
==21407==
==21407== 5084 bytes in 20 blocks are still reachable in loss record 4 of 6
==21407==    at 0x3414E222: malloc (vg_replace_malloc.c:130)
==21407==    by 0xAD29FF: g_malloc (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xAD350F: g_mem_chunk_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xAB48C5: g_ptr_array_sized_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xAB48E2: g_ptr_array_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACC98D: g_main_context_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACCB55: g_main_context_default (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACCF99: g_main_loop_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0x8048AC8: parent (dbus-test-case.c:48)
==21407==    by 0x8048D3E: main (dbus-test-case.c:145)
==21407==
==21407==
==21407== 5423 bytes in 16 blocks are still reachable in loss record 5 of 6
==21407==    at 0x3414EC61: realloc (vg_replace_malloc.c:196)
==21407==    by 0x341A3869: dbus_realloc (dbus-memory.c:596)
==21407==    by 0x341A4BC9: set_length (dbus-string.c:352)
==21407==    by 0x341A68E9: append (dbus-string.c:968)
==21407==    by 0x3416CC4D: _dbus_auth_new (dbus-auth.c:367)
==21407==    by 0x3416EC3E: _dbus_auth_client_new (dbus-auth.c:1978)
==21407==    by 0x341963B0: _dbus_transport_init_base (dbus-transport.c:108)
==21407==    by 0x34198838: _dbus_transport_new_for_fd (dbus-transport-unix.c:1152)
==21407==    by 0x341989CE: _dbus_transport_new_for_domain_socket (dbus-transport-unix.c:1232)
==21407==    by 0x34196816: _dbus_transport_open (dbus-transport.c:257)
==21407==    by 0x3417556C: _dbus_connection_open_internal (dbus-connection.c:1535)
==21407==    by 0x34170E29: dbus_bus_get (dbus-bus.c:381)
==21407==
==21407==
==21407== 75852 bytes in 1188 blocks are still reachable in loss record 6 of 6
==21407==    at 0x3414EB71: calloc (vg_replace_malloc.c:175)
==21407==    by 0xAD2A6D: g_malloc0 (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACC936: g_main_context_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACCB55: g_main_context_default (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0xACCF99: g_main_loop_new (in /usr/lib/libglib-2.0.so.0.600.4)
==21407==    by 0x8048AC8: parent (dbus-test-case.c:48)
==21407==    by 0x8048D3E: main (dbus-test-case.c:145)
==21407==
==21407== LEAK SUMMARY:
==21407==    definitely lost: 0 bytes in 0 blocks.
==21407==      possibly lost: 0 bytes in 0 blocks.
==21407==    still reachable: 89141 bytes in 1273 blocks.
==21407==         suppressed: 0 bytes in 0 blocks.

[davidz at daxter dbus]$ ==21408==
==21408== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==21408== malloc/free: in use at exit: 7633 bytes in 59 blocks.
==21408== malloc/free: 7268 allocs, 7209 frees, 159416 bytes allocated.
==21408== For counts of detected errors, rerun with: -v
==21408== searching for pointers to 59 not-freed blocks.
==21408== checked 134580 bytes.
==21408==
==21408== 24 bytes in 3 blocks are still reachable in loss record 1 of 4
==21408==    at 0x3414E222: malloc (vg_replace_malloc.c:130)
==21408==    by 0x3414EBE5: realloc (vg_replace_malloc.c:188)
==21408==    by 0x341A3869: dbus_realloc (dbus-memory.c:596)
==21408==    by 0x3419970F: _dbus_data_slot_allocator_alloc (dbus-dataslot.c:120)
==21408==    by 0x34179AF5: dbus_connection_allocate_data_slot (dbus-connection.c:4358)
==21408==    by 0x341708FD: ensure_bus_data (dbus-bus.c:276)
==21408==    by 0x34170A13: dbus_bus_register (dbus-bus.c:441)
==21408==    by 0x34170E51: dbus_bus_get (dbus-bus.c:396)
==21408==    by 0x8048BEC: child (dbus-test-case.c:91)
==21408==    by 0x8048D21: main (dbus-test-case.c:140)
==21408==
==21408==
==21408== 1114 bytes in 25 blocks are still reachable in loss record 2 of 4
==21408==    at 0x3414E222: malloc (vg_replace_malloc.c:130)
==21408==    by 0x341A3A70: dbus_malloc (dbus-memory.c:469)
==21408==    by 0x3419CC3C: _dbus_strdup (dbus-internals.c:313)
==21408==    by 0x34170F98: dbus_bus_get (dbus-bus.c:162)
==21408==    by 0x8048BEC: child (dbus-test-case.c:91)
==21408==    by 0x8048D21: main (dbus-test-case.c:140)
==21408==
==21408==
==21408== 1492 bytes in 20 blocks are still reachable in loss record 3 of 4
==21408==    at 0x3414EB71: calloc (vg_replace_malloc.c:175)
==21408==    by 0x341A39B6: dbus_malloc0 (dbus-memory.c:519)
==21408==    by 0x341A3C2E: _dbus_mem_pool_new (dbus-mempool.c:141)
==21408==    by 0x3419D087: alloc_link (dbus-list.c:63)
==21408==    by 0x3419D1D3: _dbus_list_prepend (dbus-list.c:276)
==21408==    by 0x3419D20B: _dbus_list_append (dbus-list.c:252)
==21408==    by 0x3416C009: dbus_parse_address (dbus-address.c:353)
==21408==    by 0x341754C2: _dbus_connection_open_internal (dbus-connection.c:1587)
==21408==    by 0x34170E29: dbus_bus_get (dbus-bus.c:381)
==21408==    by 0x8048BEC: child (dbus-test-case.c:91)
==21408==    by 0x8048D21: main (dbus-test-case.c:140)
==21408==
==21408==
==21408== 5003 bytes in 11 blocks are still reachable in loss record 4 of 4
==21408==    at 0x3414EC61: realloc (vg_replace_malloc.c:196)
==21408==    by 0x341A3869: dbus_realloc (dbus-memory.c:596)
==21408==    by 0x341A4BC9: set_length (dbus-string.c:352)
==21408==    by 0x341A68E9: append (dbus-string.c:968)
==21408==    by 0x3416CC4D: _dbus_auth_new (dbus-auth.c:367)
==21408==    by 0x3416EC3E: _dbus_auth_client_new (dbus-auth.c:1978)
==21408==    by 0x341963B0: _dbus_transport_init_base (dbus-transport.c:108)
==21408==    by 0x34198838: _dbus_transport_new_for_fd (dbus-transport-unix.c:1152)
==21408==    by 0x341989CE: _dbus_transport_new_for_domain_socket (dbus-transport-unix.c:1232)
==21408==    by 0x34196816: _dbus_transport_open (dbus-transport.c:257)
==21408==    by 0x3417556C: _dbus_connection_open_internal (dbus-connection.c:1535)
==21408==    by 0x34170E29: dbus_bus_get (dbus-bus.c:381)
==21408==
==21408== LEAK SUMMARY:
==21408==    definitely lost: 0 bytes in 0 blocks.
==21408==      possibly lost: 0 bytes in 0 blocks.
==21408==    still reachable: 7633 bytes in 59 blocks.
==21408==         suppressed: 0 bytes in 0 blocks.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: dbus-test-case.c
Type: text/x-csrc
Size: 3143 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/dbus/attachments/20050418/60cff7a3/dbus-test-case.c


More information about the dbus mailing list