[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 09/15] softmmu/qdev-monitor: add error handling in qdev_se
From: |
Eric Blake |
Subject: |
Re: [PATCH v2 09/15] softmmu/qdev-monitor: add error handling in qdev_set_id |
Date: |
Wed, 13 Oct 2021 16:37:44 -0500 |
User-agent: |
NeoMutt/20210205-854-613e2c |
On Wed, Oct 13, 2021 at 03:10:38PM +0200, Damien Hedde wrote:
> > > @@ -691,7 +703,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error
> > > **errp)
> > > }
> > > }
> > > - qdev_set_id(dev, g_strdup(qemu_opts_id(opts)));
> > > + /*
> > > + * set dev's parent and register its id.
> > > + * If it fails it means the id is already taken.
> > > + */
> > > + if (!qdev_set_id(dev, g_strdup(qemu_opts_id(opts)), errp)) {
> > > + goto err_del_dev;
> >
> > ...nor on this, which means the g_strdup() leaks on failure.
> >
>
> Since we strdup the id just before calling qdev_set_id.
> Maybe we should do the the strdup in qdev_set_id (and free things on error
> there too). It seems simplier than freeing things on the callee side just in
> case of an error.
Indeed. If we expected qdev_set_id() to be passed something that it
can later free, we would have used 'char *'; but because we used
'const char *' for that parameter, it really does make more sense for
the callers to pass in any string and for qdev_set_id() to do the
necessary strdup()ing, as well as clean up on error.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
- [PATCH v2 04/15] qom: Reduce use of error_propagate(), (continued)
- [PATCH v2 04/15] qom: Reduce use of error_propagate(), Kevin Wolf, 2021/10/08
- [PATCH v2 06/15] iotests/051: Fix typo, Kevin Wolf, 2021/10/08
- [PATCH v2 02/15] net/vhost-user: Fix device compatibility check, Kevin Wolf, 2021/10/08
- [PATCH v2 07/15] qdev: Avoid using string visitor for properties, Kevin Wolf, 2021/10/08
- [PATCH v2 09/15] softmmu/qdev-monitor: add error handling in qdev_set_id, Kevin Wolf, 2021/10/08
[PATCH v2 05/15] iotests/245: Fix type for iothread property, Kevin Wolf, 2021/10/08
[PATCH v2 10/15] qemu-option: Allow deleting opts during qemu_opts_foreach(), Kevin Wolf, 2021/10/08
[PATCH v2 08/15] qdev: Make DeviceState.id independent of QemuOpts, Kevin Wolf, 2021/10/08
[PATCH v2 13/15] virtio-net: Avoid QemuOpts in failover_find_primary_device(), Kevin Wolf, 2021/10/08
[PATCH v2 11/15] qdev: Add Error parameter to hide_device() callbacks, Kevin Wolf, 2021/10/08
[PATCH v2 12/15] virtio-net: Store failover primary opts pointer locally, Kevin Wolf, 2021/10/08