From b89c3d320f3e21c46e28d127ffb120210a36bd77 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Tue, 31 Aug 2010 19:14:57 +0100 Subject: libxl: correctly free Reference types in autogenerated destroy functions References types should be recursively destroyed and then the actual reference itself should be destroyed. Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- tools/libxl/gentypes.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'tools') diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py index 52cbf1f25b..538a1c3304 100644 --- a/tools/libxl/gentypes.py +++ b/tools/libxl/gentypes.py @@ -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) -- cgit v1.2.3