summaryrefslogtreecommitdiffstats
path: root/Modules/_lsprof.c
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2008-09-29 03:41:21 (GMT)
committerBrett Cannon <bcannon@gmail.com>2008-09-29 03:41:21 (GMT)
commitb2d61bde28d11ab5f31ee7cd2738828f801c68d9 (patch)
treedc5d0420f6d5d8b7b3a01bb3787c01836652b23b /Modules/_lsprof.c
parent09c01782424e61e51dbfab83886738aacd73a635 (diff)
downloadcpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.zip
cpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.tar.gz
cpython-b2d61bde28d11ab5f31ee7cd2738828f801c68d9.tar.bz2
The _lsprof module could crash the interpreter if it was given an external
timer that did not return a float and a timer was still running when the Profiler object was garbage collected. Fixes issue 3895. Code review by Benjamin Peterson.
Diffstat (limited to 'Modules/_lsprof.c')
-rw-r--r--Modules/_lsprof.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c
index 5d18c33..41c477e 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -150,7 +150,16 @@ static PY_LONG_LONG CallExternalTimer(ProfilerObject *pObj)
}
Py_DECREF(o);
if (PyErr_Occurred()) {
- PyErr_WriteUnraisable((PyObject *) pObj);
+ PyObject *context = (PyObject *)pObj;
+ /* May have been called by profiler_dealloc(). */
+ if (Py_REFCNT(context) < 1) {
+ context = PyString_FromString("profiler calling an "
+ "external timer");
+ if (context == NULL) {
+ return 0;
+ }
+ }
+ PyErr_WriteUnraisable(context);
return 0;
}
return result;