File: | build-scan/../src/network/wait-online/link.c |
Warning: | line 34, column 25 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 "sd-network.h" | |||
4 | ||||
5 | #include "alloc-util.h" | |||
6 | #include "hashmap.h" | |||
7 | #include "link.h" | |||
8 | #include "manager.h" | |||
9 | #include "string-util.h" | |||
10 | ||||
11 | int link_new(Manager *m, Link **ret, int ifindex, const char *ifname) { | |||
12 | _cleanup_(link_freep)__attribute__((cleanup(link_freep))) Link *l = NULL((void*)0); | |||
13 | int r; | |||
14 | ||||
15 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/wait-online/link.c" , 15, __PRETTY_FUNCTION__); } while (0); | |||
| ||||
16 | assert(ifindex > 0)do { if ((__builtin_expect(!!(!(ifindex > 0)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("ifindex > 0"), "../src/network/wait-online/link.c" , 16, __PRETTY_FUNCTION__); } while (0); | |||
17 | ||||
18 | r = hashmap_ensure_allocated(&m->links, NULL)internal_hashmap_ensure_allocated(&m->links, ((void*)0 ) ); | |||
19 | if (r < 0) | |||
20 | return r; | |||
21 | ||||
22 | r = hashmap_ensure_allocated(&m->links_by_name, &string_hash_ops)internal_hashmap_ensure_allocated(&m->links_by_name, & string_hash_ops ); | |||
23 | if (r < 0) | |||
24 | return r; | |||
25 | ||||
26 | l = new0(Link, 1)((Link*) calloc((1), sizeof(Link))); | |||
27 | if (!l) | |||
28 | return -ENOMEM12; | |||
29 | ||||
30 | l->manager = m; | |||
31 | ||||
32 | l->ifname = strdup(ifname); | |||
33 | if (!l->ifname) | |||
34 | return -ENOMEM12; | |||
| ||||
35 | ||||
36 | r = hashmap_put(m->links_by_name, l->ifname, l); | |||
37 | if (r < 0) | |||
38 | return r; | |||
39 | ||||
40 | l->ifindex = ifindex; | |||
41 | ||||
42 | r = hashmap_put(m->links, INT_TO_PTR(ifindex)((void *) ((intptr_t) (ifindex))), l); | |||
43 | if (r < 0) | |||
44 | return r; | |||
45 | ||||
46 | if (ret) | |||
47 | *ret = l; | |||
48 | l = NULL((void*)0); | |||
49 | ||||
50 | return 0; | |||
51 | } | |||
52 | ||||
53 | Link *link_free(Link *l) { | |||
54 | ||||
55 | if (!l) | |||
56 | return NULL((void*)0); | |||
57 | ||||
58 | if (l->manager) { | |||
59 | hashmap_remove(l->manager->links, INT_TO_PTR(l->ifindex)((void *) ((intptr_t) (l->ifindex)))); | |||
60 | hashmap_remove(l->manager->links_by_name, l->ifname); | |||
61 | } | |||
62 | ||||
63 | free(l->ifname); | |||
64 | return mfree(l); | |||
65 | } | |||
66 | ||||
67 | int link_update_rtnl(Link *l, sd_netlink_message *m) { | |||
68 | const char *ifname; | |||
69 | int r; | |||
70 | ||||
71 | assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l"), "../src/network/wait-online/link.c" , 71, __PRETTY_FUNCTION__); } while (0); | |||
72 | assert(l->manager)do { if ((__builtin_expect(!!(!(l->manager)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l->manager"), "../src/network/wait-online/link.c" , 72, __PRETTY_FUNCTION__); } while (0); | |||
73 | assert(m)do { if ((__builtin_expect(!!(!(m)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("m"), "../src/network/wait-online/link.c" , 73, __PRETTY_FUNCTION__); } while (0); | |||
74 | ||||
75 | r = sd_rtnl_message_link_get_flags(m, &l->flags); | |||
76 | if (r < 0) | |||
77 | return r; | |||
78 | ||||
79 | r = sd_netlink_message_read_string(m, IFLA_IFNAME, &ifname); | |||
80 | if (r < 0) | |||
81 | return r; | |||
82 | ||||
83 | if (!streq(l->ifname, ifname)(strcmp((l->ifname),(ifname)) == 0)) { | |||
84 | char *new_ifname; | |||
85 | ||||
86 | new_ifname = strdup(ifname); | |||
87 | if (!new_ifname) | |||
88 | return -ENOMEM12; | |||
89 | ||||
90 | hashmap_remove(l->manager->links_by_name, l->ifname); | |||
91 | free(l->ifname); | |||
92 | l->ifname = new_ifname; | |||
93 | ||||
94 | r = hashmap_put(l->manager->links_by_name, l->ifname, l); | |||
95 | if (r < 0) | |||
96 | return r; | |||
97 | } | |||
98 | ||||
99 | return 0; | |||
100 | } | |||
101 | ||||
102 | int link_update_monitor(Link *l) { | |||
103 | assert(l)do { if ((__builtin_expect(!!(!(l)),0))) log_assert_failed_realm (LOG_REALM_SYSTEMD, ("l"), "../src/network/wait-online/link.c" , 103, __PRETTY_FUNCTION__); } while (0); | |||
104 | ||||
105 | l->required_for_online = sd_network_link_get_required_for_online(l->ifindex) != 0; | |||
106 | ||||
107 | l->operational_state = mfree(l->operational_state); | |||
108 | ||||
109 | sd_network_link_get_operational_state(l->ifindex, &l->operational_state); | |||
110 | ||||
111 | l->state = mfree(l->state); | |||
112 | ||||
113 | sd_network_link_get_setup_state(l->ifindex, &l->state); | |||
114 | ||||
115 | return 0; | |||
116 | } |