]> xenbits.xensource.com Git - libvirt.git/commitdiff
esx: Fix dynamic deep copy
authorMatthias Bolte <matthias.bolte@googlemail.com>
Sat, 4 Aug 2012 17:56:17 +0000 (19:56 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 9 Aug 2012 20:31:47 +0000 (22:31 +0200)
The static deep copy allocates storage for the copy. The dynamic
version injected the dynamic dispatch after the allocation. This
triggered the invalid argument check in the dynamically dispatched
deep copy call. The deep copy function expects its dest parameter
to be a pointer to a NULL-pointer. This expectation wasn't met due
to the dispatching deep copy doing the allocation before the call.

Fix this by dynamically dispatching to the correct type before the
allocation.

src/esx/esx_vi_types.c

index 87505544aab5e09ab8318f6f084759e7cea401f5..36f31964a95919ea87a9ed5f6e66ddd727f2c8f5 100644 (file)
 
 
 #define ESX_VI__TEMPLATE__DYNAMIC_DEEP_COPY(__type, _dispatch, _deep_copy)    \
-    ESX_VI__TEMPLATE__DEEP_COPY(__type,                                       \
-      ESX_VI__TEMPLATE__DISPATCH(src->_type,                                  \
-                                 esxVI_Type_ToString(src->_type),             \
-                                 __type, _dispatch, -1)                       \
-      _deep_copy)
+    int                                                                       \
+    esxVI_##__type##_DeepCopy(esxVI_##__type **dest, esxVI_##__type *src)     \
+    {                                                                         \
+        if (dest == NULL || *dest != NULL) {                                  \
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",                      \
+                           _("Invalid argument"));                            \
+            return -1;                                                        \
+        }                                                                     \
+                                                                              \
+        if (src == NULL) {                                                    \
+            return 0;                                                         \
+        }                                                                     \
+                                                                              \
+        ESX_VI__TEMPLATE__DISPATCH(src->_type,                                \
+                                   esxVI_Type_ToString(src->_type),           \
+                                   __type, _dispatch, -1)                     \
+                                                                              \
+        if (esxVI_##__type##_Alloc(dest) < 0) {                               \
+            goto failure;                                                     \
+        }                                                                     \
+                                                                              \
+        _deep_copy                                                            \
+                                                                              \
+        return 0;                                                             \
+                                                                              \
+      failure:                                                                \
+        esxVI_##__type##_Free(dest);                                          \
+                                                                              \
+        return -1;                                                            \
+    }