]> granicus.if.org Git - python/commitdiff
Fix file handle leak
authorÉric Araujo <merwok@netwok.org>
Sun, 1 May 2011 00:05:58 +0000 (02:05 +0200)
committerÉric Araujo <merwok@netwok.org>
Sun, 1 May 2011 00:05:58 +0000 (02:05 +0200)
Lib/distutils/command/sdist.py

index 0c3b0b55bf264302b15ab48626257a6fd73ed0c4..cf8982bd9d4aac9f0b7c4735111d200d1f7cd0a9 100644 (file)
@@ -306,17 +306,20 @@ class sdist(Command):
                             rstrip_ws=1,
                             collapse_join=1)
 
-        while 1:
-            line = template.readline()
-            if line is None:            # end of file
-                break
-
-            try:
-                self.filelist.process_template_line(line)
-            except DistutilsTemplateError, msg:
-                self.warn("%s, line %d: %s" % (template.filename,
-                                               template.current_line,
-                                               msg))
+        try:
+            while 1:
+                line = template.readline()
+                if line is None:            # end of file
+                    break
+
+                try:
+                    self.filelist.process_template_line(line)
+                except DistutilsTemplateError, msg:
+                    self.warn("%s, line %d: %s" % (template.filename,
+                                                   template.current_line,
+                                                   msg))
+        finally:
+            template.close()
 
     def prune_file_list(self):
         """Prune off branches that might slip into the file list as created