This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Dima.Tisnek
Recipients Dima.Tisnek
Date 2014-04-09.18:24:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397067895.73.0.194150876234.issue21191@psf.upfronthosting.co.za>
In-reply-to
Content
os.fdopen() should either:
* consume file descriptor and return file/io object, or
* leave file descriptor alone and raise an exception

this invariant is broken in the following test case:
fd = os.open("/", os.O_RDONLY)
try:
    obj = os.fdopen(fd, "r")
except EnvironmentError:
    os.close(fd)  # cleanup

what happens:
fd = os.open("/", os.O_RDONLY) --> some fd
os.fdopen(fd, "r") --> exception, fd refers to a directory
os.close(fd) --> exception, no such fd


For reference:
1. invariant is held in Python 3.3.
2. following positive test case works correctly
fd = os.open("/etc/passwd", os.O_RDONLY)
try: obj = os.fdopen(fd, "r")  # success
except EnvironmentError: os.close(fd)  # not reached
3. following negative test case works correctly
fd = os.open("/etc/passwd", os.O_RDONLY)
try: obj = os.fdopen(fd, "w")  # wrong mode on purpose
except EnvironmentError: os.close(fd)  # closed ok
History
Date User Action Args
2014-04-09 18:24:55Dima.Tisneksetrecipients: + Dima.Tisnek
2014-04-09 18:24:55Dima.Tisneksetmessageid: <1397067895.73.0.194150876234.issue21191@psf.upfronthosting.co.za>
2014-04-09 18:24:55Dima.Tisneklinkissue21191 messages
2014-04-09 18:24:55Dima.Tisnekcreate