]> granicus.if.org Git - python/commitdiff
Issue #20437: Fixed 21 potential bugs when deleting objects references.
authorSerhiy Storchaka <storchaka@gmail.com>
Sun, 9 Feb 2014 11:33:53 +0000 (13:33 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Sun, 9 Feb 2014 11:33:53 +0000 (13:33 +0200)
16 files changed:
Misc/NEWS
Modules/_ctypes/_ctypes.c
Modules/_sqlite/cursor.c
Modules/posixmodule.c
Modules/pyexpat.c
Modules/readline.c
Modules/selectmodule.c
Modules/signalmodule.c
Modules/syslogmodule.c
Modules/zlibmodule.c
Objects/frameobject.c
Objects/tupleobject.c
Objects/unicodeobject.c
Python/ceval.c
Python/import.c
Python/sysmodule.c

index 1ec77a44ca0363e2bded734a2eb278d9572410fd..0b42ab945fbef31006610f1296f7c400dcdcf62e 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,8 @@ What's New in Python 3.3.4 release candidate 1?
 Core and Builtins
 -----------------
 
+- Issue #20437: Fixed 21 potential bugs when deleting objects references.
+
 - Issue #20538: UTF-7 incremental decoder produced inconsistant string when
   input was truncated in BASE64 section.
 
index 7d0d258b7a38ead150d054111f421a0ed81f3052..48351bee039c3aeb00310278936dbefc2036d06a 100644 (file)
@@ -159,10 +159,8 @@ _DictRemover_call(PyObject *myself, PyObject *args, PyObject *kw)
         if (-1 == PyDict_DelItem(self->dict, self->key))
             /* XXX Error context */
             PyErr_WriteUnraisable(Py_None);
-        Py_DECREF(self->key);
-        self->key = NULL;
-        Py_DECREF(self->dict);
-        self->dict = NULL;
+        Py_CLEAR(self->key);
+        Py_CLEAR(self->dict);
     }
     Py_INCREF(Py_None);
     return Py_None;
@@ -2930,10 +2928,8 @@ static int
 PyCFuncPtr_set_restype(PyCFuncPtrObject *self, PyObject *ob)
 {
     if (ob == NULL) {
-        Py_XDECREF(self->restype);
-        self->restype = NULL;
-        Py_XDECREF(self->checker);
-        self->checker = NULL;
+        Py_CLEAR(self->restype);
+        Py_CLEAR(self->checker);
         return 0;
     }
     if (ob != Py_None && !PyType_stgdict(ob) && !PyCallable_Check(ob)) {
@@ -2976,10 +2972,8 @@ PyCFuncPtr_set_argtypes(PyCFuncPtrObject *self, PyObject *ob)
     PyObject *converters;
 
     if (ob == NULL || ob == Py_None) {
-        Py_XDECREF(self->converters);
-        self->converters = NULL;
-        Py_XDECREF(self->argtypes);
-        self->argtypes = NULL;
+        Py_CLEAR(self->converters);
+        Py_CLEAR(self->argtypes);
     } else {
         converters = converters_from_argtypes(ob);
         if (!converters)
index 49994158db567b0bc90c4651039f1afbd6e1498d..09c13d4dbde621690755d0ef6bc27a6cf83224e7 100644 (file)
@@ -230,8 +230,7 @@ int pysqlite_build_row_cast_map(pysqlite_Cursor* self)
             if (converter != Py_None) {
                 Py_DECREF(converter);
             }
-            Py_XDECREF(self->row_cast_map);
-            self->row_cast_map = NULL;
+            Py_CLEAR(self->row_cast_map);
 
             return -1;
         }
@@ -443,8 +442,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
     self->locked = 1;
     self->reset = 0;
 
-    Py_XDECREF(self->next_row);
-    self->next_row = NULL;
+    Py_CLEAR(self->next_row);
 
     if (multiple) {
         /* executemany() */
@@ -860,8 +858,7 @@ PyObject* pysqlite_cursor_iternext(pysqlite_Cursor *self)
     if (!self->next_row) {
          if (self->statement) {
             (void)pysqlite_statement_reset(self->statement);
-            Py_DECREF(self->statement);
-            self->statement = NULL;
+            Py_CLEAR(self->statement);
         }
         return NULL;
     }
index 4b077a0188b96cb90ebea1e31b3584ccfca13f0b..e72fbcf11b4d4845cd195f302f526c8f0012dac8 100644 (file)
@@ -693,8 +693,7 @@ typedef struct {
 static void
 path_cleanup(path_t *path) {
     if (path->cleanup) {
-        Py_DECREF(path->cleanup);
-        path->cleanup = NULL;
+        Py_CLEAR(path->cleanup);
     }
 }
 
index 7e51d35e622006b46cd4940e5751016d8dc9b166..45680ae96296c18314ba3037bb1b75721e141216 100644 (file)
@@ -314,8 +314,7 @@ call_with_frame(PyCodeObject *c, PyObject* func, PyObject* args,
     }
     else {
         if (trace_frame(tstate, f, PyTrace_RETURN, res) < 0) {
-            Py_XDECREF(res);
-            res = NULL;
+            Py_CLEAR(res);
         }
     }
 #else
index bcd34f70c1c383bf937cdf24adb82829cf740b23..8fac526be3341cd331bbaf5393dea0430916b3c9 100644 (file)
@@ -231,8 +231,7 @@ set_hook(const char *funcname, PyObject **hook_var, PyObject *args)
     if (!PyArg_ParseTuple(args, buf, &function))
         return NULL;
     if (function == Py_None) {
-        Py_XDECREF(*hook_var);
-        *hook_var = NULL;
+        Py_CLEAR(*hook_var);
     }
     else if (PyCallable_Check(function)) {
         PyObject *tmp = *hook_var;
@@ -827,7 +826,7 @@ on_completion_display_matches_hook(char **matches,
         (r != Py_None && PyLong_AsLong(r) == -1 && PyErr_Occurred())) {
         goto error;
     }
-    Py_XDECREF(r); r=NULL;
+    Py_CLEAR(r);
 
     if (0) {
     error:
index c492224ecbcf32a4172f6ac4502b2cde220ca1ad..952a0919d4ba3d2cd170597165ac2b8fa75c47b1 100644 (file)
@@ -74,8 +74,7 @@ reap_obj(pylist fd2obj[FD_SETSIZE + 1])
 {
     int i;
     for (i = 0; i < FD_SETSIZE + 1 && fd2obj[i].sentinel >= 0; i++) {
-        Py_XDECREF(fd2obj[i].obj);
-        fd2obj[i].obj = NULL;
+        Py_CLEAR(fd2obj[i].obj);
     }
     fd2obj[0].sentinel = -1;
 }
index fbe1bb7a8cb0e7b9f1f63fbe8d53fb80f4a25160..704c9f591b260d8bc510896e55f37ce7129b0369 100644 (file)
@@ -1305,12 +1305,9 @@ finisignal(void)
         Py_XDECREF(func);
     }
 
-    Py_XDECREF(IntHandler);
-    IntHandler = NULL;
-    Py_XDECREF(DefaultHandler);
-    DefaultHandler = NULL;
-    Py_XDECREF(IgnoreHandler);
-    IgnoreHandler = NULL;
+    Py_CLEAR(IntHandler);
+    Py_CLEAR(DefaultHandler);
+    Py_CLEAR(IgnoreHandler);
 }
 
 
index 8b877cfdbc25bede90c0117f9b231ea6fec72e8f..fc3f37595b6ab762e43f1b2076bc8eb97b01480d 100644 (file)
@@ -197,8 +197,7 @@ syslog_closelog(PyObject *self, PyObject *unused)
 {
     if (S_log_open) {
         closelog();
-        Py_XDECREF(S_ident_o);
-        S_ident_o = NULL;
+        Py_CLEAR(S_ident_o);
         S_log_open = 0;
     }
     Py_INCREF(Py_None);
index e718795fa70582ea4c790c0217367bbb16e6f921..1d1072dcea136a1f94226695455a54d67df4f881 100644 (file)
@@ -392,8 +392,7 @@ PyZlib_compressobj(PyObject *selfptr, PyObject *args, PyObject *kwargs)
     }
 
  error:
-    Py_XDECREF(self);
-    self = NULL;
+    Py_CLEAR(self);
  success:
     if (zdict.buf != NULL)
         PyBuffer_Release(&zdict);
index 808e595157bfb5333d4f06bbd50ec85028ce0cf7..b31213098a6647f9b6ef5643522b24901758b8b4 100644 (file)
@@ -952,8 +952,7 @@ void
 PyFrame_Fini(void)
 {
     (void)PyFrame_ClearFreeList();
-    Py_XDECREF(builtin_object);
-    builtin_object = NULL;
+    Py_CLEAR(builtin_object);
 }
 
 /* Print summary info about the state of the optimized allocator */
index ec3f91b2c65f8faa7f8e9f313d29bc2ecbe95b28..123df8cef3c21b292ca7932c7021affcba6997cd 100644 (file)
@@ -866,8 +866,7 @@ _PyTuple_Resize(PyObject **pv, Py_ssize_t newsize)
     _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) {
@@ -913,8 +912,7 @@ PyTuple_Fini(void)
 #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
index beafaa44963436da679d3d2d697350dfee577cc8..e1ff999e136980c23c6a9cc723d2f0f5278c2141 100644 (file)
@@ -1846,8 +1846,7 @@ _PyUnicode_ClearStaticStrings()
 {
     _Py_Identifier *tmp, *s = static_strings;
     while (s) {
-        Py_DECREF(s->object);
-        s->object = NULL;
+        Py_CLEAR(s->object);
         tmp = s->next;
         s->next = NULL;
         s = tmp;
@@ -4082,8 +4081,7 @@ make_decode_exception(PyObject **exceptionObject,
     return;
 
 onError:
-    Py_DECREF(*exceptionObject);
-    *exceptionObject = NULL;
+    Py_CLEAR(*exceptionObject);
 }
 
 /* error handling callback helper:
@@ -6224,8 +6222,7 @@ make_encode_exception(PyObject **exceptionObject,
             goto onError;
         return;
       onError:
-        Py_DECREF(*exceptionObject);
-        *exceptionObject = NULL;
+        Py_CLEAR(*exceptionObject);
     }
 }
 
@@ -8225,8 +8222,7 @@ make_translate_exception(PyObject **exceptionObject,
             goto onError;
         return;
       onError:
-        Py_DECREF(*exceptionObject);
-        *exceptionObject = NULL;
+        Py_CLEAR(*exceptionObject);
     }
 }
 
index 73925dc41392beb1086b6c212611842de8db35c7..2b1619163bd1256a067edc9079f85f80d4fa2df2 100644 (file)
@@ -3049,8 +3049,7 @@ fast_yield:
                 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 @@ fast_yield:
             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 @@ PyEval_EvalCodeEx(PyObject *_co, PyObject *globals, PyObject *locals,
     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);
 
index e91cef83ff175aa410a60ba85a9a8df0232dd7a7..26f82cf29b455ac215847114ff6101d325b8658d 100644 (file)
@@ -253,8 +253,7 @@ imp_release_lock(PyObject *self, PyObject *noargs)
 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 @@ _PyImport_FixupExtensionObject(PyObject *mod, PyObject *name,
             /* 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)
index 222630c1693df0080932834788a093c455be5001..2f700e65071340e3537c606c7834d04fa5de6175 100644 (file)
@@ -395,8 +395,7 @@ trace_trampoline(PyObject *self, PyFrameObject *frame,
     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) {