From 34b8be0d7bd7980ee8be6ca70685788ed81b087b Mon Sep 17 00:00:00 2001
From: Feng Ni <fengni@huawei.com>
Date: Thu, 25 Jul 2019 15:20:52 +0800
Subject: [PATCH] qemu: fix potential memory leak

function virTypedParamsAddString may return -1 but alloc params,
so invoker should free it.

Signed-off-by: Feng Ni <fengni@huawei.com>
---
 src/qemu/qemu_driver.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ef2e980..5791c42 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5093,6 +5093,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
         goto cleanup;
 
     event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
+    eventParams = NULL;
+    eventNparams = 0;
 
     ret = 0;
 
@@ -5101,6 +5103,8 @@ qemuDomainPinVcpuLive(virDomainObjPtr vm,
     virCgroupFree(&cgroup_vcpu);
     VIR_FREE(str);
     virObjectEventStateQueue(driver->domainEventState, event);
+    if (eventParams)
+        virTypedParamsFree(eventParams, eventNparams);
     return ret;
 }
 
@@ -5308,6 +5312,8 @@ qemuDomainPinEmulator(virDomainPtr dom,
             goto endjob;
 
         event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
+        eventParams = NULL;
+        eventNparams = 0;
     }
 
     if (persistentDef) {
@@ -5329,6 +5335,8 @@ qemuDomainPinEmulator(virDomainPtr dom,
  cleanup:
     if (cgroup_emulator)
         virCgroupFree(&cgroup_emulator);
+    if (eventParams)
+        virTypedParamsFree(eventParams, eventNparams);
     virObjectEventStateQueue(driver->domainEventState, event);
     VIR_FREE(str);
     virBitmapFree(pcpumap);
@@ -5793,6 +5801,8 @@ qemuDomainPinIOThread(virDomainPtr dom,
             goto endjob;
 
         event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
+        eventParams = NULL;
+        eventNparams = 0;
     }
 
     if (persistentDef) {
@@ -5824,6 +5834,8 @@ qemuDomainPinIOThread(virDomainPtr dom,
  cleanup:
     if (cgroup_iothread)
         virCgroupFree(&cgroup_iothread);
+    if (eventParams)
+        virTypedParamsFree(eventParams, eventNparams);
     virObjectEventStateQueue(driver->domainEventState, event);
     VIR_FREE(str);
     virBitmapFree(pcpumap);
-- 
2.19.1

