diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-12 06:57:04 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-12 08:32:11 +0100 |
commit | 0f7f27694e34b501edbb3bbeec431953927a8217 (patch) | |
tree | 9190ba83f4a0b3e0c90109f6471273915db4e653 /src/network/networkd-address-label.c | |
parent | network: use structured initializers (diff) | |
download | systemd-0f7f27694e34b501edbb3bbeec431953927a8217.tar.xz systemd-0f7f27694e34b501edbb3bbeec431953927a8217.zip |
network: fixes related to NetworkConfigSection
- Do not allocate NetworkConfigSection when filename == NULL
- set .network element before calling hashmap_put()
- Always free NetworkConfigSection in each object.
Diffstat (limited to 'src/network/networkd-address-label.c')
-rw-r--r-- | src/network/networkd-address-label.c | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/network/networkd-address-label.c b/src/network/networkd-address-label.c index 98e40d3f6a..1392cba538 100644 --- a/src/network/networkd-address-label.c +++ b/src/network/networkd-address-label.c @@ -11,18 +11,6 @@ #include "parse-util.h" #include "socket-util.h" -int address_label_new(AddressLabel **ret) { - _cleanup_(address_label_freep) AddressLabel *addrlabel = NULL; - - addrlabel = new0(AddressLabel, 1); - if (!addrlabel) - return -ENOMEM; - - *ret = TAKE_PTR(addrlabel); - - return 0; -} - void address_label_free(AddressLabel *label) { if (!label) return; @@ -50,31 +38,38 @@ static int address_label_new_static(Network *network, const char *filename, unsi assert(ret); assert(!!filename == (section_line > 0)); - r = network_config_section_new(filename, section_line, &n); - if (r < 0) - return r; + if (filename) { + r = network_config_section_new(filename, section_line, &n); + if (r < 0) + return r; - label = hashmap_get(network->address_labels_by_section, n); - if (label) { - *ret = TAKE_PTR(label); + label = hashmap_get(network->address_labels_by_section, n); + if (label) { + *ret = TAKE_PTR(label); - return 0; + return 0; + } } - r = address_label_new(&label); - if (r < 0) - return r; - - label->section = TAKE_PTR(n); + label = new(AddressLabel, 1); + if (!label) + return -ENOMEM; - r = hashmap_put(network->address_labels_by_section, label->section, label); - if (r < 0) - return r; + *label = (AddressLabel) { + .network = network, + }; - label->network = network; LIST_APPEND(labels, network->address_labels, label); network->n_address_labels++; + if (filename) { + label->section = TAKE_PTR(n); + + r = hashmap_put(network->address_labels_by_section, label->section, label); + if (r < 0) + return r; + } + *ret = TAKE_PTR(label); return 0; |