rpc: handle param_int, plug memory leaks

The RPC code had several latent memory leaks and an attempt to
free the wrong string, but thankfully nothing triggered them
(blkiotune was the only one returning a string, and always as
the last parameter).  Also, our cleanups for rpcgen ended up
nuking a line of code that renders VIR_TYPED_PARAM_INT broken,
because it was the only use of 'i' in a function, even though
it was a member usage rather than a standalone declaration.

* daemon/remote.c (remoteSerializeTypedParameters): Free the
correct array element.
(remoteDispatchDomainGetSchedulerParameters)
(remoteDispatchDomainGetSchedulerParametersFlags)
(remoteDispatchDomainBlockStatsFlags)
(remoteDispatchDomainGetMemoryParameters): Don't leak strings.
* src/rpc/genprotocol.pl: Don't nuke member-usage of 'buf' or 'i'.
This commit is contained in:
Eric Blake 2011-12-20 08:22:25 -07:00
parent f8616336a3
commit 4e394dea1f
2 changed files with 14 additions and 17 deletions

View File

@ -759,7 +759,7 @@ cleanup:
if (val) {
for (i = 0; i < nparams; i++) {
VIR_FREE(val[i].field);
if (params[i].type == VIR_TYPED_PARAM_STRING)
if (val[i].value.type == VIR_TYPED_PARAM_STRING)
VIR_FREE(val[i].value.remote_typed_param_value_u.s);
}
VIR_FREE(val);
@ -898,9 +898,10 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom)
virDomainFree(dom);
VIR_FREE(params);
return rv;
no_memory:
@ -953,9 +954,10 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom)
virDomainFree(dom);
VIR_FREE(params);
return rv;
no_memory:
@ -1092,7 +1094,6 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
{
virTypedParameterPtr params = NULL;
virDomainPtr dom = NULL;
int i;
const char *path = args->path;
int nparams = args->nparams;
unsigned int flags;
@ -1140,17 +1141,12 @@ success:
rv = 0;
cleanup:
if (rv < 0) {
if (rv < 0)
virNetMessageSaveError(rerr);
if (ret->params.params_val) {
for (i = 0; i < nparams; i++)
VIR_FREE(ret->params.params_val[i].field);
VIR_FREE(ret->params.params_val);
}
}
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom)
virDomainFree(dom);
VIR_FREE(params);
return rv;
}
@ -1623,9 +1619,10 @@ success:
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom)
virDomainFree(dom);
VIR_FREE(params);
return rv;
}

View File

@ -67,12 +67,12 @@ while (<RPCGEN>) {
# Note: The body of the function is in @function.
# Remove decl of buf, if buf isn't used in the function.
my @uses = grep /\bbuf\b/, @function;
@function = grep !/\bbuf\b/, @function if @uses == 1;
my @uses = grep /[^.>]\bbuf\b/, @function;
@function = grep !/[^.>]\bbuf\b/, @function if @uses == 1;
# Remove decl of i, if i isn't used in the function.
@uses = grep /\bi\b/, @function;
@function = grep !/\bi\b/, @function if @uses == 1;
@uses = grep /[^.>]\bi\b/, @function;
@function = grep !/[^.>]\bi\b/, @function if @uses == 1;
# (char **)&objp->... gives:
# warning: dereferencing type-punned pointer will break