From: Andrew Cooper Date: Sat, 16 May 2020 12:10:07 +0000 (+0100) Subject: x86/hvm: Fix memory leaks in hvm_copy_context_and_params() X-Git-Tag: archive/raspbian/4.14.0+80-gd101b417b7-1+rpi1^2~63^2~254 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=3d6e92e309987c9e33177c9ccd155e58dbd5d0db;p=xen.git x86/hvm: Fix memory leaks in hvm_copy_context_and_params() Any error from hvm_save() or hvm_set_param() leaks the c.data allocation. Spotted by Coverity. Fixes: 353744830 "x86/hvm: introduce hvm_copy_context_and_params" Signed-off-by: Andrew Cooper Reviewed-by: Jan Beulich --- diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 814b7020d8..0a3797ef6e 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -5318,7 +5318,7 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src) return -ENOMEM; if ( (rc = hvm_save(src, &c)) ) - return rc; + goto out; for ( i = 0; i < HVM_NR_PARAMS; i++ ) { @@ -5328,11 +5328,13 @@ int hvm_copy_context_and_params(struct domain *dst, struct domain *src) continue; if ( (rc = hvm_set_param(dst, i, value)) ) - return rc; + goto out; } c.cur = 0; rc = hvm_load(dst, &c); + + out: vfree(c.data); return rc;