]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
simplify block of codes
authorAlex Jia <ajia@redhat.com>
Tue, 31 Jan 2012 03:20:40 +0000 (11:20 +0800)
committerAlex Jia <ajia@redhat.com>
Wed, 1 Feb 2012 02:57:56 +0000 (10:57 +0800)
Using new function 'virTypedParameterArrayClear' to simplify block of codes.

* daemon/remote.c, src/remote/remote_driver.c: simplify codes.

Signed-off-by: Alex Jia <ajia@redhat.com>
daemon/remote.c
src/remote/remote_driver.c

index cb8423a33e52db51046a4b593b20b2f0189487cd..e7d9b2fd9f0be00f206662bfa1654f5881d9c34e 100644 (file)
@@ -848,11 +848,7 @@ remoteDeserializeTypedParameters(remote_typed_param *args_params_val,
 
 cleanup:
     if (rv < 0) {
-        int j;
-        for (j = 0; j < i; ++j) {
-            if (params[j].type == VIR_TYPED_PARAM_STRING)
-                VIR_FREE(params[j].value.s);
-        }
+        virTypedParameterArrayClear(params, i);
         VIR_FREE(params);
     }
     return params;
index 61b96e9a43ce5bbe961aacf0b1bf2c391826b6bc..031becda671b7217aa4ac1585eb70fa440bcb048 100644 (file)
@@ -46,6 +46,7 @@
 #include "virfile.h"
 #include "command.h"
 #include "intprops.h"
+#include "virtypedparam.h"
 
 #define VIR_FROM_THIS VIR_FROM_REMOTE
 
@@ -1417,12 +1418,8 @@ remoteDeserializeTypedParameters(remote_typed_param *ret_params_val,
     rv = 0;
 
 cleanup:
-    if (rv < 0) {
-        int j;
-        for (j = 0; j < i; j++)
-            if (params[j].type == VIR_TYPED_PARAM_STRING)
-                VIR_FREE(params[j].value.s);
-    }
+    if (rv < 0)
+        virTypedParameterArrayClear(params, i);
     return rv;
 }
 
@@ -2384,15 +2381,9 @@ static int remoteDomainGetCPUStats(virDomainPtr domain,
 
     rv = ret.nparams;
 cleanup:
-    if (rv < 0) {
-        int max = nparams * ncpus;
-        int i;
+    if (rv < 0)
+        virTypedParameterArrayClear(params, nparams * ncpus);
 
-        for (i = 0; i < max; i++) {
-            if (params[i].type == VIR_TYPED_PARAM_STRING)
-                VIR_FREE(params[i].value.s);
-        }
-    }
     xdr_free ((xdrproc_t) xdr_remote_domain_get_cpu_stats_ret,
               (char *) &ret);
 done: