We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cabb466 commit 6f5f3b6Copy full SHA for 6f5f3b6
include/boost/python/object_core.hpp
@@ -419,6 +419,16 @@ inline api::object_base& api::object_base::operator=(api::object_base const& rhs
419
420
inline api::object_base::~object_base()
421
{
422
+#ifdef Py_GIL_DISABLED
423
+ // This is a not very elegant fix for a problem that occurs with the
424
+ // free-threaded build of Python. If this is called when the interpreter
425
+ // has already been finalized, the thread-state can be null. Unlike the
426
+ // GIL-enabled build, Py_DECREF() requires a valid thread-state. This
427
+ // causes a memory leak, rather than crash, which seems preferable.
428
+ if (PyThreadState_GetUnchecked() == NULL) {
429
+ return;
430
+ }
431
+#endif
432
assert( Py_REFCNT(m_ptr) > 0 );
433
Py_DECREF(m_ptr);
434
}
0 commit comments