From a76157dca6ba0d063a88cf4c0b6ac132881001b1 Mon Sep 17 00:00:00 2001
From: Vinay Sajip <vinay_sajip@yahoo.co.uk>
Date: Fri, 15 Nov 2013 20:40:27 +0000
Subject: [PATCH] Issue #19523: Closed FileHandler leak which occurred when
 delay was set.

---
 Lib/logging/__init__.py | 4 +++-
 Misc/NEWS               | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/Lib/logging/__init__.py b/Lib/logging/__init__.py
index 4cef66fa13..7f94e39f0f 100644
--- a/Lib/logging/__init__.py
+++ b/Lib/logging/__init__.py
@@ -976,8 +976,10 @@ class FileHandler(StreamHandler):
                 self.flush()
                 if hasattr(self.stream, "close"):
                     self.stream.close()
-                StreamHandler.close(self)
                 self.stream = None
+            # Issue #19523: call unconditionally to
+            # prevent a handler leak when delay is set
+            StreamHandler.close(self)
         finally:
             self.release()
 
diff --git a/Misc/NEWS b/Misc/NEWS
index 9f99095924..d5d0637fb4 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,8 @@ Core and Builtins
 Library
 -------
 
+- Issue #19523: Closed FileHandler leak which occurred when delay was set.
+
 - Issue #13674: Prevented time.strftime from crashing on Windows when given
   a year before 1900 and a format of %y.
 
-- 
2.40.0