Issue #20437: Fixed 43 potential bugs when deleting objects references.
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 00f2e47..a3c185e 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -881,8 +881,7 @@
_Py_ForgetReference((PyObject *) v);
/* DECREF items deleted by shrinkage */
for (i = newsize; i < oldsize; i++) {
- Py_XDECREF(v->ob_item[i]);
- v->ob_item[i] = NULL;
+ Py_CLEAR(v->ob_item[i]);
}
sv = PyObject_GC_Resize(PyTupleObject, v, newsize);
if (sv == NULL) {
@@ -928,8 +927,7 @@
#if PyTuple_MAXSAVESIZE > 0
/* empty tuples are used all over the place and applications may
* rely on the fact that an empty tuple is a singleton. */
- Py_XDECREF(free_list[0]);
- free_list[0] = NULL;
+ Py_CLEAR(free_list[0]);
(void)PyTuple_ClearFreeList();
#endif
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 5ce9c88..09e41b9 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -3520,8 +3520,7 @@
goto onError;
return;
onError:
- Py_DECREF(*exceptionObject);
- *exceptionObject = NULL;
+ Py_CLEAR(*exceptionObject);
}
}
@@ -4826,8 +4825,7 @@
goto onError;
return;
onError:
- Py_DECREF(*exceptionObject);
- *exceptionObject = NULL;
+ Py_CLEAR(*exceptionObject);
}
}