Skip to content

Commit bebdbd2

Browse files
committed
fix: only apply leak on 3.9.0
1 parent 61e40f6 commit bebdbd2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

include/pybind11/pybind11.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,15 @@ class cpp_function : public function {
466466
}
467467
if (rec->def) {
468468
std::free(const_cast<char *>(rec->def->ml_doc));
469-
//delete rec->def;
469+
// Python 3.9.0 decref's these in the wrong order; rec->def
470+
// If loaded on 3.9.0, let these leak (use Python 3.9.1 to fix)
471+
// See https://github.com/python/cpython/pull/22670
472+
#if !defined(PYPY_VERSION) && PY_MAJOR_VERSION == 3 && PY_MINOR_VERISON == 9
473+
if(Py_GetVersion()[4] != '0')
474+
delete rec->def;
475+
#else
476+
delete rec->def;
477+
#endif
470478
}
471479
delete rec;
472480
rec = next;

0 commit comments

Comments
 (0)