[PATCH 2/3] examples: domtop: Avoid leaking memory

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

 



Use the virTypedParamsFree unconditionally as it handles NULL well and
has the benefit of freeing a typed parameter array even if it wasn't yet
assigned, but only allocated.
---
 examples/domtop/domtop.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/examples/domtop/domtop.c b/examples/domtop/domtop.c
index 7661057..4ac7889 100644
--- a/examples/domtop/domtop.c
+++ b/examples/domtop/domtop.c
@@ -334,12 +334,8 @@ do_top(virConnectPtr conn,

     ret = 0;
  cleanup:
-    if (max_id > 0) {
-        if (now_nparams > 0)
-            virTypedParamsFree(now_params, now_nparams * max_id);
-        if (then_nparams > 0)
-            virTypedParamsFree(then_params, then_nparams * max_id);
-    }
+    virTypedParamsFree(now_params, now_nparams * max_id);
+    virTypedParamsFree(then_params, then_nparams * max_id);
     if (dom)
         virDomainFree(dom);
     return ret;
-- 
2.0.0

--
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]