File tree Expand file tree Collapse file tree
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ Fixes possible crash on :class: `types.CodeType ` deallocation.
Original file line number Diff line number Diff line change @@ -745,6 +745,10 @@ _PyCode_New(struct _PyCodeConstructor *con)
745745 return NULL ;
746746 }
747747
748+ #ifdef Py_GIL_DISABLED
749+ co -> _co_unique_id = _Py_INVALID_UNIQUE_ID ;
750+ #endif
751+
748752 if (init_code (co , con ) < 0 ) {
749753 Py_DECREF (co );
750754 return NULL ;
@@ -2545,15 +2549,17 @@ code_dealloc(PyObject *self)
25452549 FT_CLEAR_WEAKREFS (self , co -> co_weakreflist );
25462550 free_monitoring_data (co -> _co_monitoring );
25472551#ifdef Py_GIL_DISABLED
2548- // The first element always points to the mutable bytecode at the end of
2549- // the code object, which will be freed when the code object is freed.
2550- for (Py_ssize_t i = 1 ; i < co -> co_tlbc -> size ; i ++ ) {
2551- char * entry = co -> co_tlbc -> entries [i ];
2552- if (entry != NULL ) {
2553- PyMem_Free (entry );
2552+ if (co -> co_tlbc != NULL ) {
2553+ // The first element always points to the mutable bytecode at the end of
2554+ // the code object, which will be freed when the code object is freed.
2555+ for (Py_ssize_t i = 1 ; i < co -> co_tlbc -> size ; i ++ ) {
2556+ char * entry = co -> co_tlbc -> entries [i ];
2557+ if (entry != NULL ) {
2558+ PyMem_Free (entry );
2559+ }
25542560 }
2561+ PyMem_Free (co -> co_tlbc );
25552562 }
2556- PyMem_Free (co -> co_tlbc );
25572563#endif
25582564 PyObject_Free (co );
25592565}
You can’t perform that action at this time.
0 commit comments