From: Lennart Poettering Date: Wed, 24 Feb 2016 20:37:42 +0000 (+0100) Subject: network: hashmap_put() can fail X-Git-Tag: v230~185^2~57 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=21b3926840b22c738a5e575f089485732e1cbd28;p=thirdparty%2Fsystemd.git network: hashmap_put() can fail Let's properly handle hashmap_put() failing. --- diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index e065a5a5a9e..ab9b777d9a8 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -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;