[libvirt] [PATCH 07/13] src/qemu: Utilize more of VIR_(APPEND|INSERT|DELETE)_ELEMENT

Eric Blake eblake at redhat.com
Fri Mar 7 21:05:08 UTC 2014


On 03/07/2014 02:46 AM, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/qemu/qemu_command.c      | 90 ++++++++++++++++++--------------------------
>  src/qemu/qemu_conf.c         |  8 +---
>  src/qemu/qemu_conf.h         |  2 +-
>  src/qemu/qemu_driver.c       | 10 ++---
>  src/qemu/qemu_monitor_json.c |  2 +-
>  src/qemu/qemu_monitor_text.c |  3 +-
>  6 files changed, 46 insertions(+), 69 deletions(-)
> 
> diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
> index 611d21d..648cf29 100644
> --- a/src/qemu/qemu_command.c
> +++ b/src/qemu/qemu_command.c
> @@ -10981,15 +10981,16 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
>                  }
>  
>                  if (j == dom->clock.ntimers) {
> -                    if (VIR_REALLOC_N(dom->clock.timers, j + 1) < 0 ||
> -                        VIR_ALLOC(dom->clock.timers[j]) < 0)
> +                    virDomainTimerDefPtr timer;
> +                    if (VIR_ALLOC(timer) < 0 ||
> +                        VIR_APPEND_ELEMENT_COPY(dom->clock.timers,
> +                                                dom->clock.ntimers, timer) < 0)
>                          goto cleanup;

Memory leak if timer is allocated but the append fails.

> +++ b/src/qemu/qemu_driver.c
> @@ -4044,17 +4044,17 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
>                   */
>                  virDomainVcpuPinDefPtr vcpupin = NULL;
>  
> -                if (VIR_REALLOC_N(vm->def->cputune.vcpupin,
> -                                  vm->def->cputune.nvcpupin + 1) < 0)
> -                    goto cleanup;
> -
>                  if (VIR_ALLOC(vcpupin) < 0)
>                      goto cleanup;
>  
>                  vcpupin->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN);
>                  virBitmapCopy(vcpupin->cpumask, vm->def->cpumask);
>                  vcpupin->vcpuid = i;
> -                vm->def->cputune.vcpupin[vm->def->cputune.nvcpupin++] = vcpupin;
> +                if (VIR_APPEND_ELEMENT_COPY(vm->def->cputune.vcpupin,
> +                                            vm->def->cputune.nvcpupin, vcpupin) < 0) {
> +                    virBitmapFree(vcpupin->cpumask);
> +                    VIR_FREE(vcpupin);
> +                }

Missing a 'goto error;'.

ACK with those fixed.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20140307/2e24559e/attachment-0001.sig>


More information about the libvir-list mailing list