chiark / gitweb /
udev: link-config - fix mem leak
[elogind.git] / src / udev / net / link-config.c
index 8215c40d5d2cd9730353f0c61cb50dcd2b05d231..a9acc3ddb7f3173058a07209f4680abb16abba54 100644 (file)
@@ -118,6 +118,7 @@ static void link_configs_free(link_config_ctx *ctx) {
                 free(link->match_type);
                 free(link->description);
                 free(link->alias);
+                free(link->name_policy);
 
                 free(link);
         }
@@ -140,12 +141,17 @@ void link_config_ctx_free(link_config_ctx *ctx) {
 
 static int load_link(link_config_ctx *ctx, const char *filename) {
         _cleanup_free_ link_config *link = NULL;
-        _cleanup_fclose_ FILE *file;
+        _cleanup_fclose_ FILE *file = NULL;
         int r;
 
         assert(ctx);
         assert(filename);
 
+        if (null_or_empty_path(filename)) {
+                log_debug("skipping empty file: %s", filename);
+                return 0;
+        }
+
         file = fopen(filename, "re");
         if (!file) {
                 if (errno == ENOENT)
@@ -199,7 +205,8 @@ static bool enable_name_policy(void) {
 
 int link_config_load(link_config_ctx *ctx) {
         int r;
-        char **files, **f;
+        _cleanup_strv_free_ char **files;
+        char **f;
 
         link_configs_free(ctx);
 
@@ -273,22 +280,6 @@ static bool mac_is_random(struct udev_device *device) {
         return type == 1;
 }
 
-static bool mac_is_permanent(struct udev_device *device) {
-        const char *s;
-        unsigned type;
-        int r;
-
-        s = udev_device_get_sysattr_value(device, "addr_assign_type");
-        if (!s)
-                return true; /* if we don't know, assume it is permanent */
-        r = safe_atou(s, &type);
-        if (r < 0)
-                return true;
-
-        /* check for NET_ADDR_PERM */
-        return type == 0;
-}
-
 static int get_mac(struct udev_device *device, bool want_random, struct ether_addr *mac) {
         int r;
 
@@ -384,7 +375,7 @@ int link_config_apply(link_config_ctx *ctx, link_config *config, struct udev_dev
 
         switch (config->mac_policy) {
                 case MACPOLICY_PERSISTENT:
-                        if (!mac_is_permanent(device)) {
+                        if (mac_is_random(device)) {
                                 r = get_mac(device, false, &generated_mac);
                                 if (r < 0)
                                         return r;