File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -369,6 +369,15 @@ class cpp_function : public function {
369369 }
370370
371371 m_ptr = PyCFunction_NewEx (rec->def , rec_capsule.ptr (), scope_module.ptr ());
372+
373+ #if PY_VERSION_HEX >= 0x03090000
374+ weakref (m_ptr, cpp_function ([rec_capsule](handle wr) {
375+ rec_capsule.dec_ref ();
376+ wr.dec_ref ();
377+ })).release ();
378+ rec_capsule.inc_ref ();
379+ #endif
380+
372381 if (!m_ptr)
373382 pybind11_fail (" cpp_function::cpp_function(): Could not allocate function object" );
374383 } else {
@@ -466,7 +475,7 @@ class cpp_function : public function {
466475 }
467476 if (rec->def ) {
468477 std::free (const_cast <char *>(rec->def ->ml_doc ));
469- // delete rec->def;
478+ delete rec->def ;
470479 }
471480 delete rec;
472481 rec = next;
You can’t perform that action at this time.
0 commit comments