]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: Make it obvious that hypervAddEmbeddedParam() consumes an argument
authorMichal Privoznik <mprivozn@redhat.com>
Thu, 15 Oct 2020 13:31:51 +0000 (15:31 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 19 Oct 2020 09:13:10 +0000 (11:13 +0200)
Upon successful return hypervAddEmbeddedParam() transfers
ownership of @table argument to @params. But because it takes
only simple pointer (which hides this ownership transfer) it
doesn't clear the @table pointer.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Matt Coleman <matt@datto.com>
src/hyperv/hyperv_driver.c
src/hyperv/hyperv_wmi.c
src/hyperv/hyperv_wmi.h

index dd08e573c0c88e3f00542adb3ba0744659652238..cae284db0b3fe54e381a1b14aa05ad17eeebf877 100644 (file)
@@ -1794,14 +1794,14 @@ hypervDomainSetMemoryFlags(virDomainPtr domain, unsigned long memory,
 
     if (priv->wmiVersion == HYPERV_WMI_VERSION_V1) {
         if (hypervAddEmbeddedParam(params, priv, "ResourceSettingData",
-                    memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
+                                   &memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
             hypervFreeEmbeddedParam(memResource);
             goto cleanup;
         }
 
     } else if (priv->wmiVersion == HYPERV_WMI_VERSION_V2) {
         if (hypervAddEmbeddedParam(params, priv, "ResourceSettings",
-                    memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
+                                   &memResource, Msvm_MemorySettingData_WmiInfo) < 0) {
             hypervFreeEmbeddedParam(memResource);
             goto cleanup;
         }
index 779f4265b54e8c402253dff828ad518a3021f818..41579858dec32d68f12affae97f477b334ff46fa 100644 (file)
@@ -362,15 +362,22 @@ hypervSetEmbeddedProperty(virHashTablePtr table, const char *name, char *value)
  * @params: Params list to add to
  * @priv: hypervPrivate object associated with the connection
  * @name: Name of the parameter
- * @table: table of properties to add
+ * @table: pointer to table of properties to add
  * @info: WmiInfo of the object to serialize
  *
  * Add a virHashTable containing object properties as an embedded param to
- * an invocation list. Returns -1 on failure, 0 on success.
+ * an invocation list.
+ *
+ * Upon successfull return the @table is consumed and the pointer is cleared out.
+ *
+ * Returns -1 on failure, 0 on success.
  */
 int
-hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *priv,
-        const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr info)
+hypervAddEmbeddedParam(hypervInvokeParamsListPtr params,
+                       hypervPrivate *priv,
+                       const char *name,
+                       virHashTablePtr *table,
+                       hypervWmiClassInfoListPtr info)
 {
     hypervParamPtr p = NULL;
     hypervWmiClassInfoPtr classInfo = NULL;
@@ -385,7 +392,7 @@ hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *priv,
     p = &params->params[params->nbParams];
     p->type = HYPERV_EMBEDDED_PARAM;
     p->embedded.name = name;
-    p->embedded.table = table;
+    p->embedded.table = g_steal_pointer(table);
     p->embedded.info = classInfo;
     params->nbParams++;
 
index 20749f2a39997894ce660f9802cf41ba004cc771..fb19a7f375fe29e1841c4b6ecce129267b6a8307 100644 (file)
@@ -149,8 +149,11 @@ virHashTablePtr hypervCreateEmbeddedParam(hypervPrivate *priv,
 int hypervSetEmbeddedProperty(virHashTablePtr table, const char *name,
         char *value);
 
-int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params, hypervPrivate *priv,
-        const char *name, virHashTablePtr table, hypervWmiClassInfoListPtr info);
+int hypervAddEmbeddedParam(hypervInvokeParamsListPtr params,
+                           hypervPrivate *priv,
+                           const char *name,
+                           virHashTablePtr *table,
+                           hypervWmiClassInfoListPtr info);
 
 void hypervFreeEmbeddedParam(virHashTablePtr p);