[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH 6/8] gentypes: set pointer to NULL



If the dispose_fn of a type is "free" it means it should be later set to
NULL.

Signed-off-by: Wei Liu <wei.liu2@xxxxxxxxxx>
Cc: Ian Campbell <ian.campbell@xxxxxxxxxx>
Cc: Ian Jackson <ian.jackson@xxxxxxxxxxxxx>
---
 tools/libxl/gentypes.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/tools/libxl/gentypes.py b/tools/libxl/gentypes.py
index 804cb59..64dc7aa 100644
--- a/tools/libxl/gentypes.py
+++ b/tools/libxl/gentypes.py
@@ -78,14 +78,20 @@ def libxl_C_type_dispose(ty, v, indent = "    ", parent = 
None):
             raise Exception("Array type must have a parent")
         if ty.elem_type.dispose_fn is not None:
             s += "{\n"
-            s += "    int i;\n"
-            s += "    for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
+            s += "    if (%s) {\n" % (ty.pass_arg(v, parent is None),)
+            s += "        int i;\n"
+            s += "        for (i=0; i<%s; i++)\n" % (parent + ty.lenvar.name)
             s += libxl_C_type_dispose(ty.elem_type, v+"[i]",
-                                      indent + "        ", parent)
+                                      indent + "            ", parent)
         if ty.dispose_fn is not None:
             if ty.elem_type.dispose_fn is not None:
-                s += "    "
+                s += "        "
             s += "%s(%s);\n" % (ty.dispose_fn, ty.pass_arg(v, parent is None))
+            if ty.dispose_fn == "free":
+                if ty.elem_type.dispose_fn is not None: s += "    "
+                s += "    %s = NULL;\n" % (ty.pass_arg(v, parent is None),)
+        if ty.elem_type.dispose_fn is not None:
+            s += "    }\n"
         if ty.elem_type.dispose_fn is not None:
             s += "}\n"
     elif isinstance(ty, idl.Struct) and (parent is None or ty.dispose_fn is 
None):
@@ -95,7 +101,8 @@ def libxl_C_type_dispose(ty, v, indent = "    ", parent = 
None):
     else:
         if ty.dispose_fn is not None:
             s += "%s(%s);\n" % (ty.dispose_fn, ty.pass_arg(v, parent is None))
-
+            if ty.dispose_fn == "free":
+                s += "%s = NULL;\n" % (ty.pass_arg(v, parent is None),)
     if s != "":
         s = indent + s
     return s.replace("\n", "\n%s" % indent).rstrip(indent)
-- 
1.9.1


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.