From 432afe3f14418ea5d2d69e62d678ef5bb08caaa1 Mon Sep 17 00:00:00 2001
From: Xu Yandong <xuyandong2@huawei.com>
Date: Wed, 15 Apr 2020 11:55:43 +0800
Subject: cgroup: cleanup eventParams when virTypedParamsAddULLong failed

Function virTypedParamsAddULLong use realloc to gain memory,
and doesn't free it when failed. so we need free eventParams to
prevent a memory leak.

Signed-off-by: Xu Yandong <xuyandong2@huawei.com>
---
 src/qemu/qemu_cgroup.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index c0e30f6..057f871 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -904,8 +904,11 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
             if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                         &eventMaxparams,
                                         VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES,
-                                        val) < 0)
+                                        val) < 0) {
+                if (eventParams)
+                    virTypedParamsFree(eventParams, eventNparams);
                 return -1;
+            }
 
             event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
         }
-- 
2.23.0

