summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-10-05 19:47:39 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-10-05 19:47:39 +0200
commit172bb90bce0354ed9a2d1e62bbe3daee45b32058 (patch)
treeb0a5561b6394b7ab603fa4495294f576c171eb0b
parent4958d3012f703139329af3c0c1c63eca4a3e8e23 (diff)
device: duplicate the config earlier to avoid using stale data
-rw-r--r--device.c9
1 files changed, 7 insertions, 2 deletions
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);