]> granicus.if.org Git - python/commitdiff
bpo-38400 Don't check for NULL linked list pointers in _PyObject_IsFreed (GH-16630)
authorPablo Galindo <Pablogsal@gmail.com>
Mon, 7 Oct 2019 23:43:14 +0000 (00:43 +0100)
committerGitHub <noreply@github.com>
Mon, 7 Oct 2019 23:43:14 +0000 (00:43 +0100)
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.

Objects/object.c

index ae76e33e1f4f1fce372d1e8c2e6475b20fc20bce..2c8e823f05ee9414284cf5d7a2cc08ab958bd90c 100644 (file)
@@ -454,9 +454,12 @@ _PyObject_IsFreed(PyObject *op)
     /* ignore op->ob_ref: its value can have be modified
        by Py_INCREF() and Py_DECREF(). */
 #ifdef Py_TRACE_REFS
-    if (_PyMem_IsPtrFreed(op->_ob_next) || _PyMem_IsPtrFreed(op->_ob_prev)) {
+    if (op->_ob_next != NULL && _PyMem_IsPtrFreed(op->_ob_next)) {
         return 1;
     }
+    if (op->_ob_prev != NULL && _PyMem_IsPtrFreed(op->_ob_prev)) {
+         return 1;
+     }
 #endif
     return 0;
 }