Issue #20437: Fixed 21 potential bugs when deleting objects references.
diff --git a/Python/ceval.c b/Python/ceval.c
index 73925dc..2b16191 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3049,8 +3049,7 @@
                 if (call_trace(tstate->c_tracefunc,
                                tstate->c_traceobj, f,
                                PyTrace_RETURN, retval)) {
-                    Py_XDECREF(retval);
-                    retval = NULL;
+                    Py_CLEAR(retval);
                     why = WHY_EXCEPTION;
                 }
             }
@@ -3068,8 +3067,7 @@
             else if (call_trace(tstate->c_profilefunc,
                                 tstate->c_profileobj, f,
                                 PyTrace_RETURN, retval)) {
-                Py_XDECREF(retval);
-                retval = NULL;
+                Py_CLEAR(retval);
                 /* why = WHY_EXCEPTION; */
             }
         }
@@ -3426,8 +3424,7 @@
     if (co->co_flags & CO_GENERATOR) {
         /* Don't need to keep the reference to f_back, it will be set
          * when the generator is resumed. */
-        Py_XDECREF(f->f_back);
-        f->f_back = NULL;
+        Py_CLEAR(f->f_back);
 
         PCALL(PCALL_GENERATOR);
 
diff --git a/Python/import.c b/Python/import.c
index e91cef8..26f82cf 100644
--- a/Python/import.c
+++ b/Python/import.c
@@ -253,8 +253,7 @@
 void
 _PyImport_Fini(void)
 {
-    Py_XDECREF(extensions);
-    extensions = NULL;
+    Py_CLEAR(extensions);
 #ifdef WITH_THREAD
     if (import_lock != NULL) {
         PyThread_free_lock(import_lock);
@@ -497,8 +496,7 @@
             /* Somebody already imported the module,
                likely under a different name.
                XXX this should really not happen. */
-            Py_DECREF(def->m_base.m_copy);
-            def->m_base.m_copy = NULL;
+            Py_CLEAR(def->m_base.m_copy);
         }
         dict = PyModule_GetDict(mod);
         if (dict == NULL)
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 222630c..2f700e6 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -395,8 +395,7 @@
     result = call_trampoline(tstate, callback, frame, what, arg);
     if (result == NULL) {
         PyEval_SetTrace(NULL, NULL);
-        Py_XDECREF(frame->f_trace);
-        frame->f_trace = NULL;
+        Py_CLEAR(frame->f_trace);
         return -1;
     }
     if (result != Py_None) {