Blob Blame History Raw
From 59c0e19d7df8680e36afc96756dce72435121448 Mon Sep 17 00:00:00 2001
From: Duncan Bellamy <dunk@denkimushi.com>
Date: Sun, 17 Jan 2021 03:02:24 +0100
Subject: [PATCH 1/2] Close streamed file in file_generator on destruct

---
 cherrypy/lib/__init__.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/cherrypy/lib/__init__.py b/cherrypy/lib/__init__.py
index f815f76a..0edaaf20 100644
--- a/cherrypy/lib/__init__.py
+++ b/cherrypy/lib/__init__.py
@@ -70,6 +70,11 @@ def __next__(self):
             raise StopIteration()
     next = __next__
 
+    def __del__(self):
+        """Close input on descturct."""
+        if hasattr(self.input, 'close'):
+            self.input.close()
+
 
 def file_generator_limited(fileobj, count, chunk_size=65536):
     """Yield the given file object in chunks.

From 4a6287b73539adcb7b0ae72d69644a1ced1f7eaa Mon Sep 17 00:00:00 2001
From: Duncan Bellamy <dunk@denkimushi.com>
Date: Fri, 15 Jan 2021 14:49:09 +0000
Subject: [PATCH 2/2] Close hanging fd in testHandlerToolConfigOverride

---
 cherrypy/test/test_config.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cherrypy/test/test_config.py b/cherrypy/test/test_config.py
index 5e880d87..ecd46019 100644
--- a/cherrypy/test/test_config.py
+++ b/cherrypy/test/test_config.py
@@ -221,8 +221,8 @@ def testHandlerToolConfigOverride(self):
         # the favicon in the page handler to be '../favicon.ico',
         # but then overrode it in config to be './static/dirback.jpg'.
         self.getPage('/favicon.ico')
-        self.assertBody(open(os.path.join(localDir, 'static/dirback.jpg'),
-                             'rb').read())
+        with open(os.path.join(localDir, 'static/dirback.jpg'), 'rb') as tf:
+            self.assertBody(tf.read())
 
     def test_request_body_namespace(self):
         self.getPage('/plain', method='POST', headers=[