]> xenbits.xensource.com Git - libvirt.git/commitdiff
ESX: Fix memory leak in list handling functions.
authorMatthias Bolte <matthias.bolte@googlemail.com>
Thu, 22 Oct 2009 07:47:51 +0000 (09:47 +0200)
committerMatthias Bolte <matthias.bolte@googlemail.com>
Mon, 2 Nov 2009 21:22:13 +0000 (22:22 +0100)
If an error occurs between the allocation of an item and appending it
to the list, the item leaks. Free such orphaned items in error cases.

* src/esx/esx_vi.c: free orphaned items in error cases

src/esx/esx_vi.c

index bcf110fe8cf621577ef1b3ee1f97d215c79992f9..04860e20681a47c2bfdc5f0db549ee70d28c8335 100644 (file)
@@ -959,28 +959,22 @@ esxVI_List_CastFromAnyType(virConnectPtr conn, esxVI_AnyType *anyType,
 
         esxVI_AnyType_Free(&childAnyType);
 
-        if (esxVI_AnyType_Deserialize(conn, childNode, &childAnyType) < 0) {
+        if (esxVI_AnyType_Deserialize(conn, childNode, &childAnyType) < 0 ||
+            castFromAnyTypeFunc(conn, childAnyType, &item) < 0 ||
+            esxVI_List_Append(conn, list, item) < 0) {
             goto failure;
         }
 
         item = NULL;
-
-        if (castFromAnyTypeFunc(conn, childAnyType, &item) < 0) {
-            goto failure;
-        }
-
-        if (esxVI_List_Append(conn, list, item) < 0) {
-            goto failure;
-        }
     }
 
-
   cleanup:
     esxVI_AnyType_Free(&childAnyType);
 
     return result;
 
   failure:
+    freeFunc(&item);
     freeFunc(list);
 
     result = -1;
@@ -1039,20 +1033,18 @@ esxVI_List_Deserialize(virConnectPtr conn, xmlNodePtr node, esxVI_List **list,
             goto failure;
         }
 
-        item = NULL;
-
-        if (deserializeFunc(conn, node, &item) < 0) {
+        if (deserializeFunc(conn, node, &item) < 0 ||
+            esxVI_List_Append(conn, list, item) < 0) {
             goto failure;
         }
 
-        if (esxVI_List_Append(conn, list, item) < 0) {
-            goto failure;
-        }
+        item = NULL;
     }
 
     return 0;
 
   failure:
+    freeFunc(&item);
     freeFunc(list);
 
     return -1;