diff --git a/include/pybind11/detail/type_caster_base.h b/include/pybind11/detail/type_caster_base.h index 1213b0a06..4a22eb5cc 100644 --- a/include/pybind11/detail/type_caster_base.h +++ b/include/pybind11/detail/type_caster_base.h @@ -503,8 +503,9 @@ PYBIND11_NOINLINE std::string error_string(PyObject *type, PyObject *value, PyOb int lineno = PyFrame_GetLineNumber(frame); result += " " + handle(f_code->co_filename).cast() + "(" + std::to_string(lineno) - + "): " + handle(frame->f_code->co_name).cast() + "\n"; + + "): " + handle(f_code->co_name).cast() + "\n"; frame = frame->f_back; + Py_DECREF(f_code); } #endif }