Hirokazu Yamamoto <ocean-c...@m2.ccsnet.ne.jp> added the comment: Hmm, correct me if following understanding is wrong somewhere... 1. File.close() is actually file_close(), and is calling close_the_file(). 2. Returns immediately because local_fp == f->f_fp is already NULL. The return value is None. 3. sts is non-NULL, so PyMem_Free(f->f_setbuf) happens. 4. There is no system call for FILE object, so thread won't wait for close(2) completion.
Maybe can we fix this issue by the patch like this? I moved PyMem_Free into close_the_file(), and called it only when close operation succeeded. Index: Objects/fileobject.c =================================================================== --- Objects/fileobject.c (revision 82910) +++ Objects/fileobject.c (working copy) @@ -371,9 +371,14 @@ Py_END_ALLOW_THREADS if (sts == EOF) return PyErr_SetFromErrno(PyExc_IOError); - if (sts != 0) + if (sts != 0) { + PyMem_Free(f->f_setbuf); + f->f_setbuf = NULL; return PyInt_FromLong((long)sts); + } } + PyMem_Free(f->f_setbuf); + f->f_setbuf = NULL; } Py_RETURN_NONE; } @@ -567,12 +572,7 @@ static PyObject * file_close(PyFileObject *f) { - PyObject *sts = close_the_file(f); - if (sts) { - PyMem_Free(f->f_setbuf); - f->f_setbuf = NULL; - } - return sts; + return close_the_file(f); } ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue9295> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com