]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/libsystemd/sd-bus/test-bus-queue-ref-cycle.c
debe78c7e2c21b12cd9fa4b01a22eb4d5d900ab9
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
8 static int test_ref_unref(void) {
9 sd_bus_message
*m
= NULL
;
13 /* This test will result in a memory leak in <= v240, but not on v241. Hence to be really useful it
14 * should be run through a leak tracker such as valgrind. */
16 r
= sd_bus_open_system(&bus
);
18 return log_tests_skipped("Failed to connect to bus");
20 /* Create a message and enqueue it (this shouldn't send it though as the connection setup is not complete yet) */
21 assert_se(sd_bus_message_new_method_call(bus
, &m
, "foo.bar", "/foo", "quux.quux", "waldo") >= 0);
22 assert_se(sd_bus_send(bus
, m
, NULL
) >= 0);
24 /* Let's now unref the message first and the bus second. */
25 m
= sd_bus_message_unref(m
);
26 bus
= sd_bus_unref(bus
);
28 /* We should have a memory leak now on <= v240. Let's do this again, but destroy in the opposite
29 * order. On v240 that too should be a leak. */
31 r
= sd_bus_open_system(&bus
);
33 return log_tests_skipped("Failed to connect to bus");
35 assert_se(sd_bus_message_new_method_call(bus
, &m
, "foo.bar", "/foo", "quux.quux", "waldo") >= 0);
36 assert_se(sd_bus_send(bus
, m
, NULL
) >= 0);
38 /* Let's now unref things in the opposite order */
39 bus
= sd_bus_unref(bus
);
40 m
= sd_bus_message_unref(m
);
45 static int run(int argc
, char *argv
[]) {
48 test_setup_logging(LOG_INFO
);
57 DEFINE_MAIN_FUNCTION(run
);