fix memory leak in EvalWithTempExprNode
authorStefan Behnel <scoder@users.berlios.de>
Thu, 29 Jan 2009 21:48:02 +0000 (22:48 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Thu, 29 Jan 2009 21:48:02 +0000 (22:48 +0100)
Cython/Compiler/UtilNodes.py

index 497ce7e598dc0ee15b3892374764c77e75848602..1125657425777de69b5d34eab5276795778aa634 100644 (file)
@@ -164,14 +164,18 @@ class EvalWithTempExprNode(ExprNodes.NewTempExprNode):
 
     def generate_evaluation_code(self, code):
         self.temp_expression.generate_evaluation_code(code)
-        if self.temp_expression.is_temp:
+        result_in_temp = self.temp_expression.result_in_temp()
+        temp_type = self.temp_expression.type
+        if result_in_temp:
             temp = self.temp_expression.result()
         else:
             self.temp_expression.make_owned_reference(code)
             temp = code.funcstate.allocate_temp(
-                self.temp_expression.type, manage_ref=True)
+                temp_type, manage_ref=True)
             code.putln("%s = %s;" % (temp, self.temp_expression.result()))
         self.lazy_temp.result_code = temp
         self.subexpression.generate_evaluation_code(code)
-        if not self.temp_expression.is_temp:
+        if not result_in_temp:
+            if temp_type.is_pyobject:
+                code.put_decref_clear(temp, temp_type)
             code.funcstate.release_temp(temp)