1 parent 61fe449 commit 2e63a16Copy full SHA for 2e63a16
1 file changed
src/c/misc_thread_common.h
@@ -265,6 +265,13 @@ static PyTypeObject ThreadCanary_Type = {
265
266
static void init_cffi_tls_zombie(void)
267
{
268
+ /* thread_canary objects are created with PyObject_New(&ThreadCanary_Type);
269
+ the type must be readied so it has a valid metatype (ob_type). Otherwise
270
+ introspection of a canary from another module dereferences a NULL metatype
271
+ and crashes. */
272
+ if (PyType_Ready(&ThreadCanary_Type) < 0)
273
+ return; /* error set; PyInit__cffi_backend checks PyErr_Occurred() */
274
+
275
cffi_zombie_head.zombie_next = &cffi_zombie_head;
276
cffi_zombie_head.zombie_prev = &cffi_zombie_head;
277
cffi_zombie_lock = PyThread_allocate_lock();
0 commit comments