fix ticket #631: temp leak when deleting slices
authorStefan Behnel <scoder@users.berlios.de>
Sun, 19 Dec 2010 18:55:56 +0000 (19:55 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 19 Dec 2010 18:55:56 +0000 (19:55 +0100)
Cython/Compiler/ExprNodes.py
tests/run/delete.pyx

index 2ecddeb4356a0ad7db0a02fb39c8b2097509477a..c0440641ae4794bfe38100bff6037528b47b5de8 100755 (executable)
@@ -2605,6 +2605,7 @@ class SliceIndexNode(ExprNode):
                 self.start_code(),
                 self.stop_code()))
         self.generate_subexpr_disposal_code(code)
+        self.free_subexpr_temps(code)
 
     def generate_slice_guard_code(self, code, target_size):
         if not self.base.type.is_array:
index b0626581bbf5575df687b50173b0452a0fbbf71c..2aabbf425cf8f7cab475d1b30892d54904b8e93a 100644 (file)
@@ -60,3 +60,23 @@ def del_list_int(L, int i):
     """
     del L[i]
     return L
+
+def del_temp_slice(a):
+    """
+    >>> class A(object):
+    ...     attr = [1,2,3]
+    >>> a = A()
+    >>> a.attr
+    [1, 2, 3]
+    >>> del_temp_slice(a)
+    []
+    >>> a.attr
+    []
+    >>> del_temp_slice(a)
+    []
+    >>> a.attr
+    []
+    """
+    while a.attr:
+        del a.attr[:]
+    return a.attr