[libvirt] [PATCH 06/10] conf: Introduce virDomainDeviceInfoNew()

Peter Krempa pkrempa at redhat.com
Fri Jun 30 11:04:39 UTC 2017


On Thu, Jun 29, 2017 at 20:03:59 +0200, Andrea Bolognani wrote:
> It allocates and initializes a virDomainDeviceInfo struct
> in one fell swoop.
> 
> Signed-off-by: Andrea Bolognani <abologna at redhat.com>
> ---
>  src/conf/device_conf.c | 13 +++++++++++++
>  src/conf/device_conf.h |  1 +
>  2 files changed, 14 insertions(+)
> 
> diff --git a/src/conf/device_conf.c b/src/conf/device_conf.c
> index 4644580..6ead830 100644
> --- a/src/conf/device_conf.c
> +++ b/src/conf/device_conf.c
> @@ -32,6 +32,19 @@
>  
>  #define VIR_FROM_THIS VIR_FROM_DEVICE
>  
> +virDomainDeviceInfoPtr
> +virDomainDeviceInfoNew(void)
> +{
> +    virDomainDeviceInfoPtr info;
> +
> +    if (VIR_ALLOC(info) < 0)
> +        return NULL;
> +
> +    virDomainDeviceInfoClear(info);

This is a lot of duplicated 0 setting. Given a quick scroll to the other
*New function ... we only set parameters which are non-null. 

The only code path calling the clearing fucntion which is not in a
fucntion which then frees the object completely is in
virDomainDeviceInfoParseXML. I don't think we need to do it here and
additionally the objects are not reused thus you should not need to set
anything non-null anywhere else.

ACK to the wrapper except for the call to virDomainDeviceInfoClear
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: Digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20170630/f0d86e78/attachment-0001.sig>


More information about the libvir-list mailing list