networkd: immediately transfer ownership of route->section
The code was not incorrect previously, but I think it's easier to follow the ownership (and the code is more likely to remain correct when updated later on), if freeing of NetworkConfigSection* is immediately made the responsibility of route_free(), so instead of relying on route_free() not freeing ->section if adding to the network hashmap failed, make this freeing unconditional.
This commit is contained in:
parent
f4859fc74c
commit
fd45e522dd
|
@ -110,6 +110,7 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
|
||||||
|
|
||||||
if (section_line > 0) {
|
if (section_line > 0) {
|
||||||
route->section = n;
|
route->section = n;
|
||||||
|
n = NULL;
|
||||||
|
|
||||||
r = hashmap_put(network->routes_by_section, n, route);
|
r = hashmap_put(network->routes_by_section, n, route);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -122,7 +123,6 @@ int route_new_static(Network *network, const char *filename, unsigned section_li
|
||||||
|
|
||||||
*ret = route;
|
*ret = route;
|
||||||
route = NULL;
|
route = NULL;
|
||||||
n = NULL;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -137,12 +137,12 @@ void route_free(Route *route) {
|
||||||
assert(route->network->n_static_routes > 0);
|
assert(route->network->n_static_routes > 0);
|
||||||
route->network->n_static_routes--;
|
route->network->n_static_routes--;
|
||||||
|
|
||||||
if (route->section) {
|
if (route->section)
|
||||||
hashmap_remove(route->network->routes_by_section, route->section);
|
hashmap_remove(route->network->routes_by_section, route->section);
|
||||||
network_config_section_free(route->section);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
network_config_section_free(route->section);
|
||||||
|
|
||||||
if (route->link) {
|
if (route->link) {
|
||||||
set_remove(route->link->routes, route);
|
set_remove(route->link->routes, route);
|
||||||
set_remove(route->link->routes_foreign, route);
|
set_remove(route->link->routes_foreign, route);
|
||||||
|
|
Loading…
Reference in a new issue