summaryrefslogtreecommitdiff
path: root/softmmu/qdev-monitor.c
diff options
context:
space:
mode:
authorKevin Wolf <kwolf@redhat.com>2021-10-08 15:34:35 +0200
committerKevin Wolf <kwolf@redhat.com>2021-10-15 16:06:35 +0200
commit163f384752dd9125ce7eb1b2edf00b23f0a54557 (patch)
tree59527155773e38b387748fd2c195618daf25d3ea /softmmu/qdev-monitor.c
parentc34efecedd0552ee8b830402241e19daebb22aec (diff)
qdev: Make DeviceState.id independent of QemuOpts
DeviceState.id is a pointer to a string that is stored in the QemuOpts object DeviceState.opts and freed together with it. We want to create devices without going through QemuOpts in the future, so make this a separately allocated string. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20211008133442.141332-9-kwolf@redhat.com> Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Tested-by: Peter Krempa <pkrempa@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'softmmu/qdev-monitor.c')
-rw-r--r--softmmu/qdev-monitor.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c
index 672f87ed4f..b7c2d69207 100644
--- a/softmmu/qdev-monitor.c
+++ b/softmmu/qdev-monitor.c
@@ -592,7 +592,8 @@ static BusState *qbus_find(const char *path, Error **errp)
return bus;
}
-void qdev_set_id(DeviceState *dev, const char *id)
+/* Takes ownership of @id, will be freed when deleting the device */
+void qdev_set_id(DeviceState *dev, char *id)
{
if (id) {
dev->id = id;
@@ -690,7 +691,7 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)
}
}
- qdev_set_id(dev, qemu_opts_id(opts));
+ qdev_set_id(dev, g_strdup(qemu_opts_id(opts)));
/* set properties */
if (qemu_opt_foreach(opts, set_property, dev, errp)) {