]>
Commit | Line | Data |
---|---|---|
db9ecf05 | 1 | /* SPDX-License-Identifier: LGPL-2.1-or-later */ |
5cdf13c7 | 2 | |
f68a2622 | 3 | #include "sd-bus.h" |
4b70aedc LP |
4 | |
5 | #include "main-func.h" | |
4b70aedc LP |
6 | #include "tests.h" |
7 | ||
f68a2622 | 8 | static int test_ref_unref(void) { |
4b70aedc LP |
9 | sd_bus_message *m = NULL; |
10 | sd_bus *bus = NULL; | |
11 | int r; | |
12 | ||
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. */ | |
15 | ||
16 | r = sd_bus_open_system(&bus); | |
17 | if (r < 0) | |
18 | return log_tests_skipped("Failed to connect to bus"); | |
19 | ||
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); | |
23 | ||
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); | |
27 | ||
5238e957 | 28 | /* We should have a memory leak now on <= v240. Let's do this again, but destroy in the opposite |
4b70aedc LP |
29 | * order. On v240 that too should be a leak. */ |
30 | ||
31 | r = sd_bus_open_system(&bus); | |
32 | if (r < 0) | |
33 | return log_tests_skipped("Failed to connect to bus"); | |
34 | ||
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); | |
37 | ||
38 | /* Let's now unref things in the opposite order */ | |
39 | bus = sd_bus_unref(bus); | |
40 | m = sd_bus_message_unref(m); | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
f68a2622 ZJS |
45 | static int run(int argc, char *argv[]) { |
46 | int r; | |
47 | ||
48 | test_setup_logging(LOG_INFO); | |
49 | ||
50 | r = test_ref_unref(); | |
51 | if (r < 0) | |
52 | return r; | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
4b70aedc | 57 | DEFINE_MAIN_FUNCTION(run); |