device: duplicate the config earlier to avoid using stale data
authorFelix Fietkau <nbd@openwrt.org>
Wed, 5 Oct 2011 17:47:39 +0000 (19:47 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Wed, 5 Oct 2011 17:47:39 +0000 (19:47 +0200)
device.c

index b260d50e5c66f45f9838715c36d4f9407d29f163..91a78670e6099f7799e6a4c89ade2dc7b1f60e4c 100644 (file)
--- a/device.c
+++ b/device.c
@@ -354,19 +354,24 @@ device_create(const char *name, const struct device_type *type,
        enum dev_change_type change;
 
        D(DEVICE, "Create new device '%s' (%s)\n", name, type->name);
+       config = config_memdup(config);
+       if (!config)
+               return NULL;
+
        odev = device_get(name, false);
        if (odev) {
                change = device_check_config(odev, config);
                switch (change) {
                case DEV_CONFIG_APPLIED:
                        free(odev->config);
-                       odev->config = config_memdup(config);
+                       odev->config = config;
                        if (odev->present) {
                                device_set_present(odev, false);
                                device_set_present(odev, true);
                        }
                        /* fall through */
                case DEV_CONFIG_NO_CHANGE:
+                       free(config);
                        return odev;
                case DEV_CONFIG_RECREATE:
                        break;
@@ -374,7 +379,7 @@ device_create(const char *name, const struct device_type *type,
        }
 
        dev = type->create(config);
-       dev->config = config_memdup(config);
+       dev->config = config;
        if (odev)
                device_replace(dev, odev);