[libvirt] [PATCHv2] simplify block of codes

From: Alex Jia <ajia@redhat.com> 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 | 6 +----- src/remote/remote_driver.c | 16 ++++------------ 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/daemon/remote.c b/daemon/remote.c index cb8423a..e7d9b2f 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -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; diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 61b96e9..15a20ff 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -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, *nparams); return rv; } @@ -2386,12 +2383,7 @@ static int remoteDomainGetCPUStats(virDomainPtr domain, cleanup: if (rv < 0) { int max = nparams * ncpus; - int i; - - for (i = 0; i < max; i++) { - if (params[i].type == VIR_TYPED_PARAM_STRING) - VIR_FREE(params[i].value.s); - } + virTypedParameterArrayClear(params, max); } xdr_free ((xdrproc_t) xdr_remote_domain_get_cpu_stats_ret, (char *) &ret); -- 1.7.1

On 01/29/2012 08:54 PM, ajia@redhat.com wrote:
From: Alex Jia <ajia@redhat.com>
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 | 6 +----- src/remote/remote_driver.c | 16 ++++------------ 2 files changed, 5 insertions(+), 17 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
+++ b/src/remote/remote_driver.c @@ -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, *nparams);
Are you sure 'i == *nparmas'? To match the previous code, this should be: if (rv < 0) virTypedParameterArrayClear(params, i);
@@ -2386,12 +2383,7 @@ static int remoteDomainGetCPUStats(virDomainPtr domain, cleanup: if (rv < 0) { int max = nparams * ncpus; - int i; - - for (i = 0; i < max; i++) { - if (params[i].type == VIR_TYPED_PARAM_STRING) - VIR_FREE(params[i].value.s); - } + virTypedParameterArrayClear(params, max);
Here, I'd simplify slightly; no need for a temporary variable max that is only used once. Just call: virTypedParameterArrayClear(params, nparams * ncpus); ACK with those changes. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (2)
-
ajia@redhat.com
-
Eric Blake