fix resource leaks when writing exported header/api files
authorStefan Behnel <scoder@users.berlios.de>
Wed, 29 Dec 2010 19:26:04 +0000 (20:26 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 29 Dec 2010 19:26:04 +0000 (20:26 +0100)
Cython/Compiler/ModuleNode.py

index 6cb0d5feb34c654742e2cad2cbb0a1c448107d80..65bec8309d4f696b8ba559ccfe784a7bc1d574ad 100644 (file)
@@ -139,7 +139,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             h_code.putln("")
             h_code.putln("#endif")
 
-            h_code.copyto(open_new_file(result.h_file))
+            f = open_new_file(result.h_file)
+            try:
+                h_code.copyto(f)
+            finally:
+                f.close()
 
     def generate_public_declaration(self, entry, h_code, i_code):
         h_code.putln("%s %s;" % (
@@ -222,7 +226,11 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode):
             h_code.putln("")
             h_code.putln("#endif")
 
-            h_code.copyto(open_new_file(result.api_file))
+            f = open_new_file(result.api_file)
+            try:
+                h_code.copyto(f)
+            finally:
+                f.close()
 
     def generate_cclass_header_code(self, type, h_code):
         h_code.putln("%s DL_IMPORT(PyTypeObject) %s;" % (