network: fix potential memleaks related to set_put()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 Aug 2019 23:56:37 +0000 (08:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 10 Aug 2019 23:57:01 +0000 (08:57 +0900)
src/network/networkd-address.c
src/network/networkd-link.c
src/network/networkd-route.c
src/network/networkd-routing-policy-rule.c

index a207bb0..e6f30a2 100644 (file)
@@ -260,6 +260,8 @@ static int address_add_internal(Link *link, Set **addresses,
         r = set_put(*addresses, address);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return -EEXIST;
 
         address->link = link;
 
index 5c01494..6bcb078 100644 (file)
@@ -1945,6 +1945,8 @@ static int link_append_to_master(Link *link, NetDev *netdev) {
         r = set_put(master->slaves, link);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return 0;
 
         link_ref(link);
         return 0;
index 8cc8080..8a16e91 100644 (file)
@@ -399,6 +399,8 @@ static int route_add_internal(
         r = set_put(*routes, route);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return -EEXIST;
 
         route->link = link;
 
index 31a49ed..1864a5a 100644 (file)
@@ -209,7 +209,11 @@ int routing_policy_rule_make_local(Manager *m, RoutingPolicyRule *rule) {
                 if (r < 0)
                         return r;
 
-                return set_put(m->rules, rule);
+                r = set_put(m->rules, rule);
+                if (r < 0)
+                        return r;
+                if (r == 0)
+                        routing_policy_rule_free(rule);
         }
 
         return -ENOENT;
@@ -265,6 +269,8 @@ static int routing_policy_rule_add_internal(Manager *m, Set **rules, RoutingPoli
         r = set_put(*rules, rule);
         if (r < 0)
                 return r;
+        if (r == 0)
+                return -EEXIST;
 
         if (ret)
                 *ret = rule;
@@ -1180,8 +1186,8 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
                         log_warning_errno(r, "Failed to add RPDB rule to saved DB, ignoring: %s", p);
                         continue;
                 }
-
-                rule = NULL;
+                if (r > 0)
+                        rule = NULL;
         }
 
         return 0;