[libvirt] [PATCH 22/26] virsh: Resolve Coverity NEGATIVE_RETURNS

Peter Krempa pkrempa at redhat.com
Thu Sep 11 09:43:24 UTC 2014


On 09/05/14 00:26, John Ferlan wrote:
> Coverity notes that if virDomainGetCPUStats returns a negative value
> into 'nparams' then when we end up at cleanup, the call to virTypedParams
> will have issues
> 
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>  tools/virsh-domain.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index f732a6e..6fe637b 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -6650,6 +6650,7 @@ cmdCPUStats(vshControl *ctl, const vshCmd *cmd)
>      return ret;
>  
>   failed_stats:
> +    nparams = 0;
>      vshError(ctl, _("Failed to retrieve CPU statistics for domain '%s'"),
>               virDomainGetName(dom));
>      goto cleanup;
> 

This would cause a memleak if the second call to virDomainGetCPUStats
fails as it will jump to the same label, while "params" was already
allocated. You need to clear nparams explicitly on the first call that
determines the count of the returned stats field.

Peter

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


More information about the libvir-list mailing list