File: | build-scan/../src/resolve/resolved-dnssd-bus.c |
Warning: | line 118, column 32 Potential leak of memory pointed to by 'l' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | ||||
2 | #include "alloc-util.h" | |||
3 | #include "bus-util.h" | |||
4 | #include "resolved-dnssd.h" | |||
5 | #include "resolved-dnssd-bus.h" | |||
6 | #include "resolved-link.h" | |||
7 | #include "strv.h" | |||
8 | #include "user-util.h" | |||
9 | ||||
10 | int bus_dnssd_method_unregister(sd_bus_message *message, void *userdata, sd_bus_error *error) { | |||
11 | DnssdService *s = userdata; | |||
12 | DnssdTxtData *txt_data; | |||
13 | Manager *m; | |||
14 | Iterator i; | |||
15 | Link *l; | |||
16 | int r; | |||
17 | ||||
18 | assert(message)do { if ((__builtin_expect(!!(!(message)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("message"), "../src/resolve/resolved-dnssd-bus.c" , 18, __PRETTY_FUNCTION__); } while (0); | |||
19 | assert(s)do { if ((__builtin_expect(!!(!(s)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("s"), "../src/resolve/resolved-dnssd-bus.c" , 19, __PRETTY_FUNCTION__); } while (0); | |||
20 | ||||
21 | m = s->manager; | |||
22 | ||||
23 | r = bus_verify_polkit_async(message, CAP_SYS_ADMIN21, | |||
24 | "org.freedesktop.resolve1.unregister-service", | |||
25 | NULL((void*)0), false0, s->originator, | |||
26 | &m->polkit_registry, error); | |||
27 | if (r < 0) | |||
28 | return r; | |||
29 | if (r == 0) | |||
30 | return 1; /* Polkit will call us back */ | |||
31 | ||||
32 | HASHMAP_FOREACH(l, m->links, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->links), & (i), (void**)&(l), ((void*)0)); ) { | |||
33 | if (l->mdns_ipv4_scope) { | |||
34 | r = dns_scope_announce(l->mdns_ipv4_scope, true1); | |||
35 | if (r < 0) | |||
36 | log_warning_errno(r, "Failed to send goodbye messages in IPv4 scope: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/resolve/resolved-dnssd-bus.c", 36, __func__, "Failed to send goodbye messages in IPv4 scope: %m" ) : -abs(_e); }); | |||
37 | ||||
38 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->ptr_rr); | |||
39 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, s->srv_rr); | |||
40 | LIST_FOREACH(items, txt_data, s->txt_data_items)for ((txt_data) = (s->txt_data_items); (txt_data); (txt_data ) = (txt_data)->items_next) | |||
41 | dns_zone_remove_rr(&l->mdns_ipv4_scope->zone, txt_data->rr); | |||
42 | } | |||
43 | ||||
44 | if (l->mdns_ipv6_scope) { | |||
45 | r = dns_scope_announce(l->mdns_ipv6_scope, true1); | |||
46 | if (r < 0) | |||
47 | log_warning_errno(r, "Failed to send goodbye messages in IPv6 scope: %m")({ int _level = ((4)), _e = ((r)), _realm = (LOG_REALM_SYSTEMD ); (log_get_max_level_realm(_realm) >= ((_level) & 0x07 )) ? log_internal_realm(((_realm) << 10 | (_level)), _e , "../src/resolve/resolved-dnssd-bus.c", 47, __func__, "Failed to send goodbye messages in IPv6 scope: %m" ) : -abs(_e); }); | |||
48 | ||||
49 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->ptr_rr); | |||
50 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, s->srv_rr); | |||
51 | LIST_FOREACH(items, txt_data, s->txt_data_items)for ((txt_data) = (s->txt_data_items); (txt_data); (txt_data ) = (txt_data)->items_next) | |||
52 | dns_zone_remove_rr(&l->mdns_ipv6_scope->zone, txt_data->rr); | |||
53 | } | |||
54 | } | |||
55 | ||||
56 | dnssd_service_free(s); | |||
57 | ||||
58 | manager_refresh_rrs(m); | |||
59 | ||||
60 | return sd_bus_reply_method_return(message, NULL((void*)0)); | |||
61 | } | |||
62 | ||||
63 | const sd_bus_vtable dnssd_vtable[] = { | |||
64 | SD_BUS_VTABLE_START(0){ .type = _SD_BUS_VTABLE_START, .flags = 0, .x = { .start = { .element_size = sizeof(sd_bus_vtable) }, }, }, | |||
65 | ||||
66 | SD_BUS_METHOD("Unregister", NULL, NULL, bus_dnssd_method_unregister, SD_BUS_VTABLE_UNPRIVILEGED){ .type = _SD_BUS_VTABLE_METHOD, .flags = SD_BUS_VTABLE_UNPRIVILEGED , .x = { .method = { .member = "Unregister", .signature = ((void *)0), .result = ((void*)0), .handler = bus_dnssd_method_unregister , .offset = 0, }, }, }, | |||
67 | SD_BUS_SIGNAL("Conflicted", NULL, 0){ .type = _SD_BUS_VTABLE_SIGNAL, .flags = 0, .x = { .signal = { .member = "Conflicted", .signature = ((void*)0), }, }, }, | |||
68 | ||||
69 | SD_BUS_VTABLE_END{ .type = _SD_BUS_VTABLE_END, .flags = 0, .x = { { 0 } }, } | |||
70 | }; | |||
71 | ||||
72 | int dnssd_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 *name = NULL((void*)0); | |||
74 | Manager *m = userdata; | |||
75 | DnssdService *service; | |||
76 | int r; | |||
77 | ||||
78 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-dnssd-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/resolve/resolved-dnssd-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/resolve/resolved-dnssd-bus.c" , 80, __PRETTY_FUNCTION__); } while (0); | |||
81 | assert(found)do { if ((__builtin_expect(!!(!(found)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("found"), "../src/resolve/resolved-dnssd-bus.c" , 81, __PRETTY_FUNCTION__); } while (0); | |||
82 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-dnssd-bus.c" , 82, __PRETTY_FUNCTION__); } while (0); | |||
83 | ||||
84 | r = sd_bus_path_decode(path, "/org/freedesktop/resolve1/dnssd", &name); | |||
85 | if (r <= 0) | |||
86 | return 0; | |||
87 | ||||
88 | service = hashmap_get(m->dnssd_services, name); | |||
89 | if (!service) | |||
90 | return 0; | |||
91 | ||||
92 | *found = service; | |||
93 | return 1; | |||
94 | } | |||
95 | ||||
96 | int dnssd_node_enumerator(sd_bus *bus, const char *path, void *userdata, char ***nodes, sd_bus_error *error) { | |||
97 | _cleanup_strv_free___attribute__((cleanup(strv_freep))) char **l = NULL((void*)0); | |||
98 | Manager *m = userdata; | |||
99 | DnssdService *service; | |||
100 | Iterator i; | |||
101 | unsigned c = 0; | |||
102 | int r; | |||
103 | ||||
104 | assert(bus)do { if ((__builtin_expect(!!(!(bus)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("bus"), "../src/resolve/resolved-dnssd-bus.c" , 104, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
105 | assert(path)do { if ((__builtin_expect(!!(!(path)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("path"), "../src/resolve/resolved-dnssd-bus.c" , 105, __PRETTY_FUNCTION__); } while (0); | |||
106 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/resolve/resolved-dnssd-bus.c" , 106, __PRETTY_FUNCTION__); } while (0); | |||
107 | assert(nodes)do { if ((__builtin_expect(!!(!(nodes)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("nodes"), "../src/resolve/resolved-dnssd-bus.c" , 107, __PRETTY_FUNCTION__); } while (0); | |||
108 | ||||
109 | l = new0(char*, hashmap_size(m->dnssd_services) + 1)((char**) calloc((hashmap_size(m->dnssd_services) + 1), sizeof (char*))); | |||
110 | if (!l) | |||
111 | return -ENOMEM12; | |||
112 | ||||
113 | HASHMAP_FOREACH(service, m->dnssd_services, i)for ((i) = ((Iterator) { .idx = ((2147483647 *2U +1U) - 1), . next_key = ((void*)0) }); hashmap_iterate((m->dnssd_services ), &(i), (void**)&(service), ((void*)0)); ) { | |||
114 | char *p; | |||
115 | ||||
116 | r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &p); | |||
117 | if (r < 0) | |||
118 | return r; | |||
| ||||
119 | ||||
120 | l[c++] = p; | |||
121 | } | |||
122 | ||||
123 | l[c] = NULL((void*)0); | |||
124 | *nodes = TAKE_PTR(l)({ typeof(l) _ptr_ = (l); (l) = ((void*)0); _ptr_; }); | |||
125 | ||||
126 | return 1; | |||
127 | } |