Re: [PATCH] cgroup: cleanup eventParams when virTypedParamsAddULLong failed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 9/19/19 10:02 AM, Xu Yandong wrote:
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@xxxxxxxxxx>
---
  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 ecd96efb0a..bc498e4b10 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -869,8 +869,11 @@ qemuSetupCpuCgroup(virDomainObjPtr vm)
              if (virTypedParamsAddULLong(&eventParams, &eventNparams,
                                          &eventMaxparams,
                                          VIR_DOMAIN_TUNABLE_CPU_CPU_SHARES,
-                                        val) < 0)
+                                        val) < 0) {
+                if (eventParams)

This check seems needless.

+                    virTypedParamsFree(eventParams, eventNparams);
                  return -1;
+            }
event = virDomainEventTunableNewFromObj(vm, eventParams, eventNparams);
          }



Have you actually seen a leak here or was this just found via code investigation?

Because the only way that virTypedParamsAddULLong() can fail is if VIR_RESIZE_N() called inside it fails at which point it doesn't allocate any new memory.

Michal

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux