From: Felix Fietkau Date: Wed, 5 Oct 2011 17:47:39 +0000 (+0200) Subject: device: duplicate the config earlier to avoid using stale data X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fnetifd.git;a=commitdiff_plain;h=172bb90bce0354ed9a2d1e62bbe3daee45b32058 device: duplicate the config earlier to avoid using stale data --- diff --git a/device.c b/device.c index b260d50..91a7867 100644 --- 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);