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 ocean-city
Recipients ocean-city, pitrou
Date 2010-07-18.17:35:37
SpamBayes Score 0.000671582
Marked as misclassified No
Message-id <1279474539.68.0.852084808182.issue9295@psf.upfronthosting.co.za>
In-reply-to
Content
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);
 }
History
Date User Action Args
2010-07-18 17:35:39ocean-citysetrecipients: + ocean-city, pitrou
2010-07-18 17:35:39ocean-citysetmessageid: <1279474539.68.0.852084808182.issue9295@psf.upfronthosting.co.za>
2010-07-18 17:35:38ocean-citylinkissue9295 messages
2010-07-18 17:35:38ocean-citycreate