[issue11577] testcase for exception binhex.Error

Arkady Koplyarov report at bugs.python.org
Wed Mar 16 23:46:39 CET 2011


Arkady Koplyarov <akoplyarov at rim.com> added the comment:

The testcase provided shows up a resource leakage:
-----
C:\_cpython\cpython>PCbuild\python_d.exe  -m test.regrtest test_binhex
[1/1] test_binhex
C:\_cpython\cpython\lib\unittest\case.py:574: ResourceWarning: unclosed file <_io.BufferedWriter name='@test_5592_tmp2'>
  callableObj(*args, **kwargs)
1 test OK.
-----
The resource leakage occurs in module binhex.py in binhex(inp,out) > BinHex.__init__() > _writeinfo() when the exception binhex.Error is raised in _writeinfo() at the code line:
    raise Error('Filename too long')
The issue is that when the exception is thrown the file is left unclosed.

One of possible fixes is to catch the thrown exception and close the unclosed file in the BinHex.__init__().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11577>
_______________________________________


More information about the Python-bugs-list mailing list