From: lu zhipeng <luzhipeng(a)cestc.cn>
For prevent memory leak and easier to use, So change
virDomainEventTunableNew to get virTypedParameterPtr *params
and set it = NULL.
Signed-off-by: lu zhipeng <luzhipeng(a)cestc.cn>
---
v1:
https://patchew.org/Libvirt/20220922130038.1616-1-luzhipeng@cestc.cn/
src/conf/domain_event.c | 12 ++++++------
src/conf/domain_event.h | 4 ++--
src/qemu/qemu_driver.c | 22 ++++++++++------------
src/remote/remote_driver.c | 2 +-
4 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index ff8ea2c389..97d58c2521 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -1495,7 +1495,7 @@ static virObjectEvent *
virDomainEventTunableNew(int id,
const char *name,
unsigned char *uuid,
- virTypedParameterPtr params,
+ virTypedParameterPtr *params,
int nparams)
{
virDomainEventTunable *ev;
@@ -1508,19 +1508,19 @@ virDomainEventTunableNew(int id,
id, name, uuid)))
goto error;
- ev->params = params;
+ ev->params = *params;
ev->nparams = nparams;
-
+ *params = NULL;
return (virObjectEvent *)ev;
error:
- virTypedParamsFree(params, nparams);
+ virTypedParamsFree(*params, nparams);
return NULL;
}
virObjectEvent *
virDomainEventTunableNewFromObj(virDomainObj *obj,
- virTypedParameterPtr params,
+ virTypedParameterPtr *params,
int nparams)
{
return virDomainEventTunableNew(obj->def->id,
@@ -1532,7 +1532,7 @@ virDomainEventTunableNewFromObj(virDomainObj *obj,
virObjectEvent *
virDomainEventTunableNewFromDom(virDomainPtr dom,
- virTypedParameterPtr params,
+ virTypedParameterPtr *params,
int nparams)
{
return virDomainEventTunableNew(dom->id,
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 4a9f6b988b..f4016dc1e9 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -195,11 +195,11 @@ virDomainEventDeviceRemovalFailedNewFromDom(virDomainPtr dom,
virObjectEvent *
virDomainEventTunableNewFromObj(virDomainObj *obj,
- virTypedParameterPtr params,
+ virTypedParameterPtr *params,
int nparams);
virObjectEvent *
virDomainEventTunableNewFromDom(virDomainPtr dom,
- virTypedParameterPtr params,
+ virTypedParameterPtr *params,
int nparams);
virObjectEvent *
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 94b70872d4..3db4592945 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4472,12 +4472,12 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
&eventMaxparams, paramField, str) < 0)
goto cleanup;
- event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
+ event = virDomainEventTunableNewFromObj(vm, &eventParams, eventNparams);
ret = 0;
cleanup:
virObjectEventStateQueue(driver->domainEventState, event);
+ virTypedParamsFree(eventParams, eventNparams);
return ret;
}
@@ -4681,7 +4681,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
str) < 0)
goto endjob;
- event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
+ event = virDomainEventTunableNewFromDom(dom, &eventParams, eventNparams);
}
if (persistentDef) {
@@ -4700,6 +4700,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
cleanup:
virObjectEventStateQueue(driver->domainEventState, event);
virDomainObjEndAPI(&vm);
+ virTypedParamsFree(eventParams, eventNparams);
return ret;
}
@@ -5078,7 +5079,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
&eventMaxparams, paramField, str) < 0)
goto endjob;
- event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
+ event = virDomainEventTunableNewFromDom(dom, &eventParams, eventNparams);
}
if (persistentDef) {
@@ -5106,6 +5107,7 @@ qemuDomainPinIOThread(virDomainPtr dom,
cleanup:
virObjectEventStateQueue(driver->domainEventState, event);
virDomainObjEndAPI(&vm);
+ virTypedParamsFree(eventParams, eventNparams);
return ret;
}
@@ -9633,8 +9635,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
qemuDomainSaveStatus(vm);
if (eventNparams) {
- event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
- eventNparams = 0;
+ event = virDomainEventTunableNewFromDom(dom, &eventParams, eventNparams);
virObjectEventStateQueue(driver->domainEventState, event);
}
@@ -9654,8 +9655,7 @@ qemuDomainSetSchedulerParametersFlags(virDomainPtr dom,
cleanup:
virDomainObjEndAPI(&vm);
- if (eventNparams)
- virTypedParamsFree(eventParams, eventNparams);
+ virTypedParamsFree(eventParams, eventNparams);
return ret;
}
#undef SCHED_RANGE_CHECK
@@ -16159,8 +16159,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
qemuDomainSaveStatus(vm);
if (eventNparams) {
- event = virDomainEventTunableNewFromDom(dom, eventParams, eventNparams);
- eventNparams = 0;
+ event = virDomainEventTunableNewFromDom(dom, &eventParams,
eventNparams);
virObjectEventStateQueue(driver->domainEventState, event);
}
}
@@ -16202,8 +16201,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom,
VIR_FREE(info.group_name);
VIR_FREE(conf_info.group_name);
virDomainObjEndAPI(&vm);
- if (eventNparams)
- virTypedParamsFree(eventParams, eventNparams);
+ virTypedParamsFree(eventParams, eventNparams);
return ret;
}
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index a4efe101a3..b0dba9057b 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5078,7 +5078,7 @@ remoteDomainBuildEventCallbackTunable(virNetClientProgram *prog
G_GNUC_UNUSED,
return;
}
- event = virDomainEventTunableNewFromDom(dom, params, nparams);
+ event = virDomainEventTunableNewFromDom(dom, ¶ms, nparams);
virObjectUnref(dom);
--
2.31.1