提交 4e394dea 编写于 作者: E Eric Blake

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'.
上级 f8616336
...@@ -759,7 +759,7 @@ cleanup: ...@@ -759,7 +759,7 @@ cleanup:
if (val) { if (val) {
for (i = 0; i < nparams; i++) { for (i = 0; i < nparams; i++) {
VIR_FREE(val[i].field); 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[i].value.remote_typed_param_value_u.s);
} }
VIR_FREE(val); VIR_FREE(val);
...@@ -898,9 +898,10 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS ...@@ -898,9 +898,10 @@ remoteDispatchDomainGetSchedulerParameters(virNetServerPtr server ATTRIBUTE_UNUS
cleanup: cleanup:
if (rv < 0) if (rv < 0)
virNetMessageSaveError(rerr); virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
VIR_FREE(params);
return rv; return rv;
no_memory: no_memory:
...@@ -953,9 +954,10 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE ...@@ -953,9 +954,10 @@ remoteDispatchDomainGetSchedulerParametersFlags(virNetServerPtr server ATTRIBUTE
cleanup: cleanup:
if (rv < 0) if (rv < 0)
virNetMessageSaveError(rerr); virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
VIR_FREE(params);
return rv; return rv;
no_memory: no_memory:
...@@ -1092,7 +1094,6 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED, ...@@ -1092,7 +1094,6 @@ remoteDispatchDomainBlockStatsFlags(virNetServerPtr server ATTRIBUTE_UNUSED,
{ {
virTypedParameterPtr params = NULL; virTypedParameterPtr params = NULL;
virDomainPtr dom = NULL; virDomainPtr dom = NULL;
int i;
const char *path = args->path; const char *path = args->path;
int nparams = args->nparams; int nparams = args->nparams;
unsigned int flags; unsigned int flags;
...@@ -1140,17 +1141,12 @@ success: ...@@ -1140,17 +1141,12 @@ success:
rv = 0; rv = 0;
cleanup: cleanup:
if (rv < 0) { if (rv < 0)
virNetMessageSaveError(rerr); virNetMessageSaveError(rerr);
if (ret->params.params_val) { virTypedParameterArrayClear(params, nparams);
for (i = 0; i < nparams; i++) VIR_FREE(params);
VIR_FREE(ret->params.params_val[i].field);
VIR_FREE(ret->params.params_val);
}
}
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
VIR_FREE(params);
return rv; return rv;
} }
...@@ -1623,9 +1619,10 @@ success: ...@@ -1623,9 +1619,10 @@ success:
cleanup: cleanup:
if (rv < 0) if (rv < 0)
virNetMessageSaveError(rerr); virNetMessageSaveError(rerr);
virTypedParameterArrayClear(params, nparams);
VIR_FREE(params);
if (dom) if (dom)
virDomainFree(dom); virDomainFree(dom);
VIR_FREE(params);
return rv; return rv;
} }
......
...@@ -67,12 +67,12 @@ while (<RPCGEN>) { ...@@ -67,12 +67,12 @@ while (<RPCGEN>) {
# Note: The body of the function is in @function. # Note: The body of the function is in @function.
# Remove decl of buf, if buf isn't used in the function. # Remove decl of buf, if buf isn't used in the function.
my @uses = grep /\bbuf\b/, @function; my @uses = grep /[^.>]\bbuf\b/, @function;
@function = grep !/\bbuf\b/, @function if @uses == 1; @function = grep !/[^.>]\bbuf\b/, @function if @uses == 1;
# Remove decl of i, if i isn't used in the function. # Remove decl of i, if i isn't used in the function.
@uses = grep /\bi\b/, @function; @uses = grep /[^.>]\bi\b/, @function;
@function = grep !/\bi\b/, @function if @uses == 1; @function = grep !/[^.>]\bi\b/, @function if @uses == 1;
# (char **)&objp->... gives: # (char **)&objp->... gives:
# warning: dereferencing type-punned pointer will break # warning: dereferencing type-punned pointer will break
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册