]>
git.proxmox.com Git - systemd.git/blob - src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 static int test_ref_unref(void) {
8 sd_bus_message
*m
= NULL
;
12 /* This test will result in a memory leak in <= v240, but not on v241. Hence to be really useful it
13 * should be run through a leak tracker such as valgrind. */
15 r
= sd_bus_open_system(&bus
);
17 return log_tests_skipped("Failed to connect to bus");
19 /* Create a message and enqueue it (this shouldn't send it though as the connection setup is not complete yet) */
20 assert_se(sd_bus_message_new_method_call(bus
, &m
, "foo.bar", "/foo", "quux.quux", "waldo") >= 0);
21 assert_se(sd_bus_send(bus
, m
, NULL
) >= 0);
23 /* Let's now unref the message first and the bus second. */
24 m
= sd_bus_message_unref(m
);
25 bus
= sd_bus_unref(bus
);
27 /* We should have a memory leak now on <= v240. Let's do this again, but destory in the opposite
28 * order. On v240 that too should be a leak. */
30 r
= sd_bus_open_system(&bus
);
32 return log_tests_skipped("Failed to connect to bus");
34 assert_se(sd_bus_message_new_method_call(bus
, &m
, "foo.bar", "/foo", "quux.quux", "waldo") >= 0);
35 assert_se(sd_bus_send(bus
, m
, NULL
) >= 0);
37 /* Let's now unref things in the opposite order */
38 bus
= sd_bus_unref(bus
);
39 m
= sd_bus_message_unref(m
);
44 static int run(int argc
, char *argv
[]) {
47 test_setup_logging(LOG_INFO
);
56 DEFINE_MAIN_FUNCTION(run
);