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.
This commit is contained in:
Brett Cannon 2008-09-29 03:41:21 +00:00
parent 09c0178242
commit b2d61bde28
3 changed files with 29 additions and 2 deletions

View file

@ -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;