Skip to content

Commit a360070

Browse files
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. (cherry picked from commit 36e33c3) Co-authored-by: Pablo Galindo <[email protected]>
1 parent 296383b commit a360070

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
@@ -426,9 +426,12 @@ _PyObject_IsFreed(PyObject *op)
426426
/* ignore op->ob_ref: its value can have be modified
427427
by Py_INCREF() and Py_DECREF(). */
428428
#ifdef Py_TRACE_REFS
429-
if (_PyMem_IsPtrFreed(op->_ob_next) || _PyMem_IsPtrFreed(op->_ob_prev)) {
429+
if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) {
430430
return 1;
431431
}
432+
if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) {
433+
return 1;
434+
}
432435
#endif
433436
return 0;
434437
}

0 commit comments

Comments
 (0)