]> xenbits.xensource.com Git - xen.git/commitdiff
x86/hvm: Fix memory leaks in hvm_copy_context_and_params()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Sat, 16 May 2020 12:10:07 +0000 (13:10 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 18 May 2020 14:22:53 +0000 (15:22 +0100)
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 <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
xen/arch/x86/hvm/hvm.c

index 814b7020d8735d1159ef399e3b10bcfbef3f8e2c..0a3797ef6ece3d573b532df965a11caead30d466 100644 (file)
@@ -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;