[PATCH] qemu: fix memory leak on some paths

Martin Kletzander mkletzan at redhat.com
Thu Sep 22 14:39:15 UTC 2022


On Thu, Sep 22, 2022 at 04:26:06PM +0200, Jiri Denemark wrote:
>On Thu, Sep 22, 2022 at 21:00:38 +0800, luzhipeng wrote:
>> From: lu zhipeng <luzhipeng at cestc.cn>
>>
>> virTypedParamsAddString may return -1 but alloc params,
>> so free it.
>>
>> Signed-off-by: lu zhipeng <luzhipeng at cestc.cn>
>> ---
>>  src/qemu/qemu_driver.c | 10 +++++++++-
>>  1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>> index 94b70872d4..c4501cd705 100644
>> --- a/src/qemu/qemu_driver.c
>> +++ b/src/qemu/qemu_driver.c
>> @@ -4473,11 +4473,13 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
>>          goto cleanup;
>>
>>      event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
>
>This call consumes eventParams which should not be used afterwards. Thus
>instead of
>
>> -
>> +    eventNparams = 0;
>
>we should set eventParams = NULL here...
>
>>      ret = 0;
>>
>>   cleanup:
>>      virObjectEventStateQueue(driver->domainEventState, event);
>
>... and call virTypedParamsFree unconditionally.
>
>> +    if (eventNparams)
>> +        virTypedParamsFree(eventParams, eventNparams);
>>      return ret;
>>  }
>>
>
>Alternatively, virDomainEventTunableNew could be changed to get
>virTypedParameterPtr *params and set &params = NULL itself.
>

That's what I wanted to suggest since it actually consumes the params as
it would make it more future-proof and easier to use.

>Jirka
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20220922/b068fc8f/attachment.sig>


More information about the libvir-list mailing list