m->links_by_index = hashmap_free_with_destructor(m->links_by_index, link_unref);
m->dhcp_pd_subnet_ids = set_free(m->dhcp_pd_subnet_ids);
- m->networks = ordered_hashmap_free_with_destructor(m->networks, network_unref);
+ m->networks = ordered_hashmap_free(m->networks);
/* The same object may be registered with multiple names, and netdev_detach() may drop multiple
* entries. Hence, hashmap_free_with_destructor() cannot be used. */
#include "strv.h"
#include "tclass.h"
+DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
+ network_hash_ops,
+ char, string_hash_func, string_compare_func,
+ Network, network_unref);
+
DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR(
stacked_netdevs_hash_ops,
char, string_hash_func, string_compare_func,
if (r < 0)
return r; /* network_verify() logs internally. */
- r = ordered_hashmap_ensure_put(networks, &string_hash_ops, network->name, network);
+ r = ordered_hashmap_ensure_put(networks, &network_hash_ops, network->name, network);
if (r < 0)
return log_warning_errno(r, "%s: Failed to store configuration into hashmap: %m", filename);
}
int network_reload(Manager *manager) {
- OrderedHashmap *new_networks = NULL;
+ _cleanup_ordered_hashmap_free_ OrderedHashmap *new_networks = NULL;
Network *n, *old;
int r;
r = network_load(manager, &new_networks);
if (r < 0)
- goto failure;
+ return r;
ORDERED_HASHMAP_FOREACH(n, new_networks) {
r = network_get_by_name(manager, n->name, &old);
/* Nothing updated, use the existing Network object, and drop the new one. */
r = ordered_hashmap_replace(new_networks, old->name, old);
if (r < 0)
- goto failure;
+ return r;
network_ref(old);
network_unref(n);
}
- ordered_hashmap_free_with_destructor(manager->networks, network_unref);
- manager->networks = new_networks;
+ ordered_hashmap_free_and_replace(manager->networks, new_networks);
r = manager_build_dhcp_pd_subnet_ids(manager);
if (r < 0)
return r;
return 0;
-
-failure:
- ordered_hashmap_free_with_destructor(new_networks, network_unref);
-
- return r;
}
int manager_build_dhcp_pd_subnet_ids(Manager *manager) {