File: | build-scan/../src/network/networkd-link-bus.c |
Warning: | line 61, column 33 Potential leak of memory pointed to by 'l' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* SPDX-License-Identifier: LGPL-2.1+ */ | |||
2 | ||||
3 | #include "alloc-util.h" | |||
4 | #include "bus-util.h" | |||
5 | #include "networkd-link.h" | |||
6 | #include "networkd-manager.h" | |||
7 | #include "parse-util.h" | |||
8 | #include "strv.h" | |||
9 | ||||
10 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_operational_state, link_operstate, LinkOperationalState)int property_get_operational_state(sd_bus *bus, const char *path , const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { LinkOperationalState *data = userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c" , 10, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("reply"), "../src/network/networkd-link-bus.c", 10, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-link-bus.c" , 10, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "s", link_operstate_to_string((*(data)))); }; | |||
11 | static BUS_DEFINE_PROPERTY_GET_ENUM(property_get_administrative_state, link_state, LinkState)int property_get_administrative_state(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error) { LinkState *data = userdata; do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c" , 11, __PRETTY_FUNCTION__); } while (0); do { if ((__builtin_expect (!!(!(reply)),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("reply"), "../src/network/networkd-link-bus.c", 11, __PRETTY_FUNCTION__ ); } while (0); do { if ((__builtin_expect(!!(!(data)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("data"), "../src/network/networkd-link-bus.c" , 11, __PRETTY_FUNCTION__); } while (0); return sd_bus_message_append (reply, "s", link_state_to_string((*(data)))); }; | |||
12 | ||||
13 | const sd_bus_vtable link_vtable[] = { | |||
14 | SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = { .element_size = sizeof(sd_bus_vtable) }, }, }, | |||
15 | ||||
16 | SD_BUS_PROPERTY("OperationalState", "s", property_get_operational_state, offsetof(Link, operstate), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "OperationalState", .signature = "s", .get = property_get_operational_state, .set = ((void* )0), .offset = __builtin_offsetof(Link, operstate), }, }, }, | |||
17 | SD_BUS_PROPERTY("AdministrativeState", "s", property_get_administrative_state, offsetof(Link, state), SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE){ .type = _SD_BUS_VTABLE_PROPERTY, .flags = SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE , .x = { .property = { .member = "AdministrativeState", .signature = "s", .get = property_get_administrative_state, .set = ((void *)0), .offset = __builtin_offsetof(Link, state), }, }, }, | |||
18 | ||||
19 | SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, } | |||
20 | }; | |||
21 | ||||
22 | static char *link_bus_path(Link *link) { | |||
23 | _cleanup_free___attribute__((cleanup(freep))) char *ifindex = NULL((void*)0); | |||
24 | char *p; | |||
25 | int r; | |||
26 | ||||
27 | assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("link"), "../src/network/networkd-link-bus.c" , 27, __PRETTY_FUNCTION__); } while (0); | |||
28 | assert(link->ifindex > 0)do { if ((__builtin_expect(!!(!(link->ifindex > 0)),0)) ) log_assert_failed_realm(LOG_REALM_SYSTEMD, ("link->ifindex > 0" ), "../src/network/networkd-link-bus.c", 28, __PRETTY_FUNCTION__ ); } while (0); | |||
29 | ||||
30 | if (asprintf(&ifindex, "%d", link->ifindex) < 0) | |||
31 | return NULL((void*)0); | |||
32 | ||||
33 | r = sd_bus_path_encode("/org/freedesktop/network1/link", ifindex, &p); | |||
34 | if (r < 0) | |||
35 | return NULL((void*)0); | |||
36 | ||||
37 | return p; | |||
38 | } | |||
39 | ||||
40 | int link_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { | |||
41 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0); | |||
42 | Manager *m = userdata; | |||
43 | unsigned c = 0; | |||
44 | Link *link; | |||
45 | Iterator i; | |||
46 | ||||
47 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c" , 47, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
48 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-link-bus.c" , 48, __PRETTY_FUNCTION__); } while (0); | |||
49 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-link-bus.c" , 49, __PRETTY_FUNCTION__); } while (0); | |||
50 | assert(nodes)do { if ((__builtin_expect(!!(!(nodes)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("nodes"), "../src/network/networkd-link-bus.c" , 50, __PRETTY_FUNCTION__); } while (0); | |||
51 | ||||
52 | l = new0(char*, hashmap_size(m->links) + 1)((char**) calloc((hashmap_size(m->links) + 1), sizeof(char *))); | |||
53 | if (!l) | |||
54 | return -ENOMEM12; | |||
55 | ||||
56 | HASHMAP_FOREACH(link, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->links), & (i), (void**)&(link), ((void*)0)); ) { | |||
57 | char *p; | |||
58 | ||||
59 | p = link_bus_path(link); | |||
60 | if (!p
| |||
61 | return -ENOMEM12; | |||
| ||||
62 | ||||
63 | l[c++] = p; | |||
64 | } | |||
65 | ||||
66 | l[c] = NULL((void*)0); | |||
67 | *nodes = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; }); | |||
68 | ||||
69 | return 1; | |||
70 | } | |||
71 | ||||
72 | int link_object_find(sd_bus *bus, const char *path, const char *interface, void *userdata, void **found, sd_bus_error *error) { | |||
73 | _cleanup_free___attribute__((cleanup(freep))) char *identifier = NULL((void*)0); | |||
74 | Manager *m = userdata; | |||
75 | Link *link; | |||
76 | int ifindex, r; | |||
77 | ||||
78 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/network/networkd-link-bus.c" , 78, __PRETTY_FUNCTION__); } while (0); | |||
79 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/network/networkd-link-bus.c" , 79, __PRETTY_FUNCTION__); } while (0); | |||
80 | assert(interface)do { if ((__builtin_expect(!!(!(interface)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("interface"), "../src/network/networkd-link-bus.c" , 80, __PRETTY_FUNCTION__); } while (0); | |||
81 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/networkd-link-bus.c" , 81, __PRETTY_FUNCTION__); } while (0); | |||
82 | assert(found)do { if ((__builtin_expect(!!(!(found)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("found"), "../src/network/networkd-link-bus.c" , 82, __PRETTY_FUNCTION__); } while (0); | |||
83 | ||||
84 | r = sd_bus_path_decode(path, "/org/freedesktop/network1/link", &identifier); | |||
85 | if (r <= 0) | |||
86 | return 0; | |||
87 | ||||
88 | r = parse_ifindex(identifier, &ifindex); | |||
89 | if (r < 0) | |||
90 | return 0; | |||
91 | ||||
92 | r = link_get(m, ifindex, &link); | |||
93 | if (r < 0) | |||
94 | return 0; | |||
95 | ||||
96 | *found = link; | |||
97 | ||||
98 | return 1; | |||
99 | } | |||
100 | ||||
101 | int link_send_changed(Link *link, const char *property, ...) { | |||
102 | _cleanup_free___attribute__((cleanup(freep))) char *p = NULL((void*)0); | |||
103 | char **l; | |||
104 | ||||
105 | assert(link)do { if ((__builtin_expect(!!(!(link)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("link"), "../src/network/networkd-link-bus.c" , 105, __PRETTY_FUNCTION__); } while (0); | |||
106 | assert(link->manager)do { if ((__builtin_expect(!!(!(link->manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("link->manager"), "../src/network/networkd-link-bus.c" , 106, __PRETTY_FUNCTION__); } while (0); | |||
107 | ||||
108 | if (!link->manager->bus) | |||
109 | return 0; /* replace with assert when we have kdbus */ | |||
110 | ||||
111 | l = strv_from_stdarg_alloca(property)({ char **_l; if (!property) _l = (char**) &property; else { size_t _n; va_list _ap; _n = 1; __builtin_va_start(_ap, property ); while (__builtin_va_arg(_ap, char*)) _n++; __builtin_va_end (_ap); _l = ({ do { if ((__builtin_expect(!!(!(!size_multiply_overflow (sizeof(char*), _n+1))),0))) log_assert_failed_realm(LOG_REALM_SYSTEMD , ("!size_multiply_overflow(sizeof(char*), _n+1)"), "../src/network/networkd-link-bus.c" , 111, __PRETTY_FUNCTION__); } while (0); (char**) __builtin_alloca (sizeof(char*)*(_n+1)); }); _l[_n = 0] = (char*) property; __builtin_va_start (_ap, property); for (;;) { _l[++_n] = __builtin_va_arg(_ap, char *); if (!_l[_n]) break; } __builtin_va_end(_ap); } _l; }); | |||
112 | ||||
113 | p = link_bus_path(link); | |||
114 | if (!p) | |||
115 | return -ENOMEM12; | |||
116 | ||||
117 | return sd_bus_emit_properties_changed_strv( | |||
118 | link->manager->bus, | |||
119 | p, | |||
120 | "org.freedesktop.network1.Link", | |||
121 | l); | |||
122 | } |