[New-bugs-announce] [issue4841] io's close() not handling errors correctly

Ulrich Eckhardt report at bugs.python.org
Mon Jan 5 11:29:49 CET 2009

New submission from Ulrich Eckhardt <eckhardt at satorlaser.com>:

In _fileio.c, there is the following comment: "Returns 0 on success,
errno (which is < 0) on failure." The problem here is the claim that
errno ever was less than zero, which is simply wrong.

You can see this being a problem with the following few lines:

import os, io
fd = os.open( "some existing file", os.O_RDONLY)
s1 = os.fdopen(fd)
s2 = io.open(fd)

The call to close() pulls the file from under the feet of the two stream
objects, but only the one opened with os.fdopen() actually detects that.
For the second one, errno is set, but to a positive value which isn't
detected correctly.

components: Interpreter Core
messages: 79120
nosy: eckhardt
severity: normal
status: open
title: io's close() not handling errors correctly
type: behavior
versions: Python 2.6, Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list