]> xenbits.xensource.com Git - libvirt.git/commitdiff
rpc: handle param_int, plug memory leaks
authorEric Blake <eblake@redhat.com>
Tue, 20 Dec 2011 15:22:25 +0000 (08:22 -0700)
committerEric Blake <eblake@redhat.com>
Tue, 20 Dec 2011 15:41:10 +0000 (08:41 -0700)
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'.

daemon/remote.c
src/rpc/genprotocol.pl

index e1d208c59109f3829c3baeb676ab3bfa2f563531..ad4c767d7c554cef241d0353eaee23fa5a4ab977 100644 (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;
 }
 
index 7af1b3bd124e44d4d60790d8bda6d0b98470a9ee..48383255d982067ae36099fbcee72feb54c84c4f 100755 (executable)
@@ -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