diff --git a/src/pya/pya/pya.cc b/src/pya/pya/pya.cc index 09cb9f754..81ed9633b 100644 --- a/src/pya/pya/pya.cc +++ b/src/pya/pya/pya.cc @@ -103,6 +103,7 @@ public: PythonStackTraceProvider (PyFrameObject *frame, const std::string &scope) : m_scope (scope) { + PythonRef frame_object_ref; while (frame != NULL) { #if PY_VERSION_HEX >= 0x030A0000 @@ -123,6 +124,8 @@ public: #if PY_VERSION_HEX >= 0x030A0000 frame = PyFrame_GetBack(frame); + // PyFrame_GetBack returns a strong reference, hence we need to make sure it is released + frame_object_ref = (PyObject *) frame; #else frame = frame->f_back; #endif