Bug Summary

File:build-scan/../src/resolve/resolved-dnssd-bus.c
Warning:line 118, column 32
Potential leak of memory pointed to by 'l'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name resolved-dnssd-bus.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -menable-no-infs -menable-no-nans -menable-unsafe-fp-math -fno-signed-zeros -mreassociate -freciprocal-math -fdenormal-fp-math=preserve-sign,preserve-sign -ffp-contract=fast -fno-rounding-math -ffast-math -ffinite-math-only -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -fno-split-dwarf-inlining -debugger-tuning=gdb -resource-dir /usr/lib64/clang/12.0.0 -include config.h -I systemd-resolved.p -I . -I .. -I src/basic -I ../src/basic -I src/shared -I ../src/shared -I src/systemd -I ../src/systemd -I src/journal -I ../src/journal -I src/journal-remote -I ../src/journal-remote -I src/nspawn -I ../src/nspawn -I src/resolve -I ../src/resolve -I src/timesync -I ../src/timesync -I ../src/time-wait-sync -I src/login -I ../src/login -I src/udev -I ../src/udev -I src/libudev -I ../src/libudev -I src/core -I ../src/core -I ../src/libsystemd/sd-bus -I ../src/libsystemd/sd-device -I ../src/libsystemd/sd-hwdb -I ../src/libsystemd/sd-id128 -I ../src/libsystemd/sd-netlink -I ../src/libsystemd/sd-network -I src/libsystemd-network -I ../src/libsystemd-network -I /usr/include/p11-kit-1 -D _FILE_OFFSET_BITS=64 -internal-isystem /usr/local/include -internal-isystem /usr/lib64/clang/12.0.0/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wwrite-strings -Wno-unused-parameter -Wno-missing-field-initializers -Wno-unused-result -Wno-format-signedness -Wno-error=nonnull -std=gnu99 -fconst-strings -fdebug-compilation-dir /home/mrc0mmand/repos/@redhat-plumbers/systemd-rhel8/build-scan -ferror-limit 19 -fvisibility hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -analyzer-output=html -faddrsig -o /tmp/scan-build-2021-07-16-221226-1465241-1 -x c ../src/resolve/resolved-dnssd-bus.c
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
10int 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
63const 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
72int 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
96int 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)
;
1
Assuming 'bus' is non-null
2
Taking false branch
3
Loop condition is false. Exiting loop
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)
;
4
Assuming 'path' is non-null
5
Taking false branch
6
Loop condition is false. Exiting loop
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)
;
7
Assuming 'm' is non-null
8
Taking false branch
9
Loop condition is false. Exiting loop
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)
;
10
Assuming 'nodes' is non-null
11
Taking false branch
12
Loop condition is false. Exiting loop
108
109 l = new0(char*, hashmap_size(m->dnssd_services) + 1)((char**) calloc((hashmap_size(m->dnssd_services) + 1), sizeof
(char*)))
;
13
Memory is allocated
110 if (!l)
14
Assuming 'l' is non-null
15
Taking false branch
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)); )
{
16
Loop condition is true. Entering loop body
114 char *p;
115
116 r = sd_bus_path_encode("/org/freedesktop/resolve1/dnssd", service->name, &p);
117 if (r < 0)
17
Assuming 'r' is < 0
18
Taking true branch
118 return r;
19
Potential leak of memory pointed to by 'l'
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}