[libvirt] [PATCH 5/6] xenconfig: Resolve Coverity RESOURCE_LEAK

Pavel Hrdina phrdina at redhat.com
Mon Jan 12 07:25:21 UTC 2015


On 01/09/2015 05:02 PM, John Ferlan wrote:
> Commit id '2c78051a' added xenFormatXLDomainDisks which used the
> virConfSetValue to set the 'diskVal' and handle/own the memory for
> diskVal. However, if diskVal->list == NULL, the memory for diskVal
> wouldn't be VIR_FREE()'d like other similar uses - so added the
> VIR_FREE() to resolve the memory leak.
>
> I also noted that the cleanup path should have returned -1 (like other
> uses), so I modified that as well while I was making the change.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>   src/xenconfig/xen_xl.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
> index 8d1d2a7..45c479a 100644
> --- a/src/xenconfig/xen_xl.c
> +++ b/src/xenconfig/xen_xl.c
> @@ -396,8 +396,7 @@ xenFormatXLDomainDisks(virConfPtr conf, virDomainDefPtr def)
>           if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
>               continue;
>           if (xenFormatXLDisk(diskVal, def->disks[i]) < 0)
> -
> -                goto cleanup;
> +            goto cleanup;
>       }
>
>       if (diskVal->list != NULL) {
> @@ -407,11 +406,12 @@ xenFormatXLDomainDisks(virConfPtr conf, virDomainDefPtr def)
>               goto cleanup;
>       }
>
> +    VIR_FREE(diskVal);
>       return 0;
>
>    cleanup:
>       virConfFreeValue(diskVal);
> -    return 0;
> +    return -1;
>   }
>
>
>

NACK to this one as it won't be necessary to fix this memory leak,
because the whole file will be removed by reverting the commit 2c78051a
by the new patch series to implement xl parser
<https://www.redhat.com/archives/libvir-list/2015-January/msg00268.html>.

Pavel




More information about the libvir-list mailing list