[Python-checkins] bpo-38400 Don't check for NULL linked list pointers in _PyObject_IsFreed (GH-16630)

Miss Islington (bot) webhook-mailer at python.org
Sun Jan 19 18:43:17 EST 2020

commit: a360070121836dd29b691f5d6d14bcfb371d8029
branch: 3.7
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-01-19T15:43:12-08:00

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
(cherry picked from commit 36e33c360ed7716a2b5ab2b53210da81f8ce1295)

Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>

M Objects/object.c

diff --git a/Objects/object.c b/Objects/object.c
index 8a3f8831d6e92..21fa7b56607df 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -426,9 +426,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;
+     }
     return 0;

More information about the Python-checkins mailing list