]> xenbits.xensource.com Git - libvirt.git/commitdiff
examples: domtop: Avoid leaking memory
authorPeter Krempa <pkrempa@redhat.com>
Mon, 21 Jul 2014 07:53:17 +0000 (09:53 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Mon, 21 Jul 2014 13:20:59 +0000 (15:20 +0200)
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

index 7661057b125d408d7e586bc799ab8989f29fca3b..4ac7889221cd417645e4fcc65d457ceac8b0530c 100644 (file)
@@ -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;