]> xenbits.xensource.com Git - xen.git/commitdiff
libxl: correctly free Reference types in autogenerated destroy functions
authorIan Campbell <ian.campbell@citrix.com>
Tue, 31 Aug 2010 18:14:57 +0000 (19:14 +0100)
committerIan Campbell <ian.campbell@citrix.com>
Tue, 31 Aug 2010 18:14:57 +0000 (19:14 +0100)
References types should be recursively destroyed and then the actual
reference itself should be destroyed.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>
Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/gentypes.py

index 52cbf1f25b54b5f95200da6f2c0119f613102f1f..538a1c3304998da21090caeba5d8b4c291c2d060 100644 (file)
@@ -64,6 +64,11 @@ def libxl_C_type_destroy(ty, v, reference, indent = "    ", parent = None):
         deref = v + "->"
     else:
         deref = v + "."
+        
+    if ty.passby == libxltypes.PASS_BY_REFERENCE and not reference:
+        makeref = "&"
+    else:
+        makeref = ""
 
     s = ""
     if isinstance(ty, libxltypes.KeyedUnion):
@@ -76,6 +81,8 @@ def libxl_C_type_destroy(ty, v, reference, indent = "    ", parent = None):
             s += "}\n"
     elif isinstance(ty, libxltypes.Reference):
         s += libxl_C_type_destroy(ty.ref_type, v, True, indent, v)
+        if ty.destructor_fn is not None:
+            s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)
     elif isinstance(ty, libxltypes.Struct) and (parent is None or ty.destructor_fn is None):
         for f in [f for f in ty.fields if not f.const]:
 
@@ -84,11 +91,6 @@ def libxl_C_type_destroy(ty, v, reference, indent = "    ", parent = None):
             else:
                 s += libxl_C_type_destroy(f.type, deref + f.name, False, "", deref)
     else:
-        if ty.passby == libxltypes.PASS_BY_REFERENCE and not reference:
-            makeref = "&"
-        else:
-            makeref = ""
-
         if ty.destructor_fn is not None:
             s += "%s(%s);\n" % (ty.destructor_fn, makeref + v)