From a68962a422f69683d8cd5ceb2a477ecb34c6c60c Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 29 Dec 2010 20:26:04 +0100 Subject: [PATCH] fix resource leaks when writing exported header/api files --- Cython/Compiler/ModuleNode.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 6cb0d5fe..65bec830 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -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;" % ( -- 2.26.2