summaryrefslogtreecommitdiffstats
path: root/Modules/socketmodule.c
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-29 10:38:18 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-29 10:38:18 (GMT)
commite033e06db077d5abcb4bc3729d03f8a4a09b2486 (patch)
tree04445ffa669d4d0df240d680249c7d7a7f661bd4 /Modules/socketmodule.c
parent9cbdd75ec5deda8f55edd7caab42dff65d009da2 (diff)
downloadcpython-e033e06db077d5abcb4bc3729d03f8a4a09b2486.zip
cpython-e033e06db077d5abcb4bc3729d03f8a4a09b2486.tar.gz
cpython-e033e06db077d5abcb4bc3729d03f8a4a09b2486.tar.bz2
Issue #10093: ResourceWarnings are now issued when files and sockets are
deallocated without explicit closing. These warnings are silenced by default, except in pydebug mode.
Diffstat (limited to 'Modules/socketmodule.c')
-rw-r--r--Modules/socketmodule.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c
index eeb9304..fdbf7ee 100644
--- a/Modules/socketmodule.c
+++ b/Modules/socketmodule.c
@@ -2941,8 +2941,20 @@ static PyMemberDef sock_memberlist[] = {
static void
sock_dealloc(PySocketSockObject *s)
{
- if (s->sock_fd != -1)
+ if (s->sock_fd != -1) {
+ PyObject *exc, *val, *tb;
+ Py_ssize_t old_refcount = Py_REFCNT(s);
+ ++Py_REFCNT(s);
+ PyErr_Fetch(&exc, &val, &tb);
+ if (PyErr_WarnFormat(PyExc_ResourceWarning, 1,
+ "unclosed %R", s))
+ /* Spurious errors can appear at shutdown */
+ if (PyErr_ExceptionMatches(PyExc_Warning))
+ PyErr_WriteUnraisable((PyObject *) s);
+ PyErr_Restore(exc, val, tb);
(void) SOCKETCLOSE(s->sock_fd);
+ Py_REFCNT(s) = old_refcount;
+ }
Py_TYPE(s)->tp_free((PyObject *)s);
}