mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Issue #16485: Fix file descriptor not being closed if file header patching fails on closing of aifc file.
This commit is contained in:
parent
40f12ab0c5
commit
4ed797efbc
3 changed files with 32 additions and 16 deletions
38
Lib/aifc.py
38
Lib/aifc.py
|
@ -732,22 +732,28 @@ class Aifc_write:
|
||||||
self._patchheader()
|
self._patchheader()
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self._ensure_header_written(0)
|
if self._file is None:
|
||||||
if self._datawritten & 1:
|
return
|
||||||
# quick pad to even size
|
try:
|
||||||
self._file.write(chr(0))
|
self._ensure_header_written(0)
|
||||||
self._datawritten = self._datawritten + 1
|
if self._datawritten & 1:
|
||||||
self._writemarkers()
|
# quick pad to even size
|
||||||
if self._nframeswritten != self._nframes or \
|
self._file.write(chr(0))
|
||||||
self._datalength != self._datawritten or \
|
self._datawritten = self._datawritten + 1
|
||||||
self._marklength:
|
self._writemarkers()
|
||||||
self._patchheader()
|
if self._nframeswritten != self._nframes or \
|
||||||
if self._comp:
|
self._datalength != self._datawritten or \
|
||||||
self._comp.CloseCompressor()
|
self._marklength:
|
||||||
self._comp = None
|
self._patchheader()
|
||||||
# Prevent ref cycles
|
if self._comp:
|
||||||
self._convert = None
|
self._comp.CloseCompressor()
|
||||||
self._file.close()
|
self._comp = None
|
||||||
|
finally:
|
||||||
|
# Prevent ref cycles
|
||||||
|
self._convert = None
|
||||||
|
f = self._file
|
||||||
|
self._file = None
|
||||||
|
f.close()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Internal methods.
|
# Internal methods.
|
||||||
|
|
|
@ -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
|
||||||
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).
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue