Commit 4ed797ef authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #16485: Fix file descriptor not being closed if file header patching...

Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file.
parent 40f12ab0
...@@ -732,6 +732,9 @@ class Aifc_write: ...@@ -732,6 +732,9 @@ class Aifc_write:
self._patchheader() self._patchheader()
def close(self): def close(self):
if self._file is None:
return
try:
self._ensure_header_written(0) self._ensure_header_written(0)
if self._datawritten & 1: if self._datawritten & 1:
# quick pad to even size # quick pad to even size
...@@ -745,9 +748,12 @@ class Aifc_write: ...@@ -745,9 +748,12 @@ class Aifc_write:
if self._comp: if self._comp:
self._comp.CloseCompressor() self._comp.CloseCompressor()
self._comp = None self._comp = None
finally:
# Prevent ref cycles # Prevent ref cycles
self._convert = None self._convert = None
self._file.close() f = self._file
self._file = None
f.close()
# #
# Internal methods. # Internal methods.
......
...@@ -106,6 +106,13 @@ class AIFCTest(unittest.TestCase): ...@@ -106,6 +106,13 @@ class AIFCTest(unittest.TestCase):
self.assertEqual(testfile.closed, False) self.assertEqual(testfile.closed, False)
f.close() f.close()
self.assertEqual(testfile.closed, True) self.assertEqual(testfile.closed, True)
testfile = open(TESTFN, 'wb')
fout = aifc.open(testfile, 'wb')
self.assertFalse(testfile.closed)
with self.assertRaises(aifc.Error):
fout.close()
self.assertTrue(testfile.closed)
fout.close() # do nothing
class AIFCLowLevelTest(unittest.TestCase): class AIFCLowLevelTest(unittest.TestCase):
......
...@@ -175,6 +175,9 @@ Core and Builtins ...@@ -175,6 +175,9 @@ Core and Builtins
Library Library
------- -------
- Issue #16485: Fix file descriptor not being closed if file header patching
fails on closing of aifc file.
- Issue #12065: connect_ex() on an SSL socket now returns the original errno - Issue #12065: connect_ex() on an SSL socket now returns the original errno
when the socket's timeout expires (it used to return None). when the socket's timeout expires (it used to return None).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment