network: hashmap_put() can fail

Let's properly handle hashmap_put() failing.
This commit is contained in:
Lennart Poettering 2016-02-24 21:37:42 +01:00
parent 2c289ea833
commit 21b3926840
1 changed files with 8 additions and 7 deletions

View File

@ -52,8 +52,7 @@ int route_new_static(Network *network, unsigned section, Route **ret) {
int r;
if (section) {
route = hashmap_get(network->routes_by_section,
UINT_TO_PTR(section));
route = hashmap_get(network->routes_by_section, UINT_TO_PTR(section));
if (route) {
*ret = route;
route = NULL;
@ -67,16 +66,18 @@ int route_new_static(Network *network, unsigned section, Route **ret) {
return r;
route->protocol = RTPROT_STATIC;
route->network = network;
LIST_PREPEND(routes, network->static_routes, route);
if (section) {
r = hashmap_put(network->routes_by_section, UINT_TO_PTR(route->section), route);
if (r < 0)
return r;
route->section = section;
hashmap_put(network->routes_by_section,
UINT_TO_PTR(route->section), route);
}
LIST_PREPEND(routes, network->static_routes, route);
route->network = network;
*ret = route;
route = NULL;