File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed
Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff line change @@ -2912,7 +2912,11 @@ _PyTrash_thread_deposit_object(PyThreadState *tstate, PyObject *op)
29122912#ifdef Py_GIL_DISABLED
29132913 op -> ob_tid = (uintptr_t )tstate -> delete_later ;
29142914#else
2915- * ((PyObject * * )op ) = tstate -> delete_later ;
2915+ /* Store the pointer in the refcnt field.
2916+ * As this object may still be tracked by the GC,
2917+ * it is important that we never store 0 (NULL). */
2918+ uintptr_t refcnt = (uintptr_t )tstate -> delete_later ;
2919+ * ((uintptr_t * )op ) = refcnt + 1 ;
29162920#endif
29172921 tstate -> delete_later = op ;
29182922}
@@ -2931,7 +2935,8 @@ _PyTrash_thread_destroy_chain(PyThreadState *tstate)
29312935 op -> ob_tid = 0 ;
29322936 _Py_atomic_store_ssize_relaxed (& op -> ob_ref_shared , _Py_REF_MERGED );
29332937#else
2934- tstate -> delete_later = * ((PyObject * * )op );
2938+ uintptr_t refcnt = * ((uintptr_t * )op );
2939+ tstate -> delete_later = (PyObject * )(refcnt - 1 );
29352940 op -> ob_refcnt = 0 ;
29362941#endif
29372942
You can’t perform that action at this time.
0 commit comments