From: Benjamin Peterson Date: Sat, 30 Oct 2010 23:16:28 +0000 (+0000) Subject: if FileIO.__init__ fails, close fd X-Git-Tag: v3.2a4~243 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbb0412ad179b4a94d03ce592a5bc1d40724998e;p=python if FileIO.__init__ fails, close fd --- diff --git a/Misc/NEWS b/Misc/NEWS index cadafd02b0..21dcacfdb8 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.2 Beta 1? Core and Builtins ----------------- +- If FileIO.__init__ fails, close the file descriptor. + - Issue #10221: dict.pop(k) now has a key error message that includes the missing key (same message d[k] returns for missing keys). diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index 37ff25c495..09ea80f179 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -410,6 +410,8 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds) error: ret = -1; + if (self->fd >= 0) + internal_close(self); done: Py_CLEAR(stringobj);