]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
If close() fails in file_dealloc, then print an error message to
authorPeter Astrand <astrand@lysator.liu.se>
Sun, 7 Nov 2004 14:15:28 +0000 (14:15 +0000)
committerPeter Astrand <astrand@lysator.liu.se>
Sun, 7 Nov 2004 14:15:28 +0000 (14:15 +0000)
stderr. close() can fail if the user is out-of-quota, for example.
Fixes #959379.

Objects/fileobject.c

index 34f28e32ac550a4e937e7bb94667090568eda529..c08345c04d395f69f1c412b296083f5fc2bd366d 100644 (file)
@@ -300,12 +300,19 @@ static void drop_readahead(PyFileObject *);
 static void
 file_dealloc(PyFileObject *f)
 {
+       int sts = 0;
        if (f->weakreflist != NULL)
                PyObject_ClearWeakRefs((PyObject *) f);
        if (f->f_fp != NULL && f->f_close != NULL) {
                Py_BEGIN_ALLOW_THREADS
-               (*f->f_close)(f->f_fp);
+               sts = (*f->f_close)(f->f_fp);
                Py_END_ALLOW_THREADS
+               if (sts == EOF) 
+#ifdef HAVE_STRERROR
+                       PySys_WriteStderr("close failed: [Errno %d] %s\n", errno, strerror(errno)); 
+#else
+                       PySys_WriteStderr("close failed: [Errno %d]\n", errno); 
+#endif
        }
        PyMem_Free(f->f_setbuf);
        Py_XDECREF(f->f_name);