Skip to content

Commit 36e33c3

Browse files
authored
bpo-38400 Don't check for NULL linked list pointers in _PyObject_IsFreed (GH-16630)
Some objects like Py_None are not initialized with conventional means that prepare the circular linked list pointers, leaving them unlinked from the rest of the objects. For those objects, NULL pointers does not mean that they are freed, so we need to skip the check in those cases.
1 parent 1b18455 commit 36e33c3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

Objects/object.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,9 +454,12 @@ _PyObject_IsFreed(PyObject *op)
454454
/* ignore op->ob_ref: its value can have be modified
455455
by Py_INCREF() and Py_DECREF(). */
456456
#ifdef Py_TRACE_REFS
457-
if (_PyMem_IsPtrFreed(op->_ob_next) || _PyMem_IsPtrFreed(op->_ob_prev)) {
457+
if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) {
458458
return 1;
459459
}
460+
if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) {
461+
return 1;
462+
}
460463
#endif
461464
return 0;
462465
}

0 commit comments

Comments
 (0)