]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: hashmap_put() can fail
authorLennart Poettering <lennart@poettering.net>
Wed, 24 Feb 2016 20:37:42 +0000 (21:37 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 12 Apr 2016 11:43:30 +0000 (13:43 +0200)
Let's properly handle hashmap_put() failing.

src/network/networkd-route.c

index e065a5a5a9ef94c28b352f7479faafe6f5822508..ab9b777d9a8faf1eecf819156009b48ccd2247d2 100644 (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;