]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.6] bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077) (GH...
authorSerhiy Storchaka <storchaka@gmail.com>
Tue, 11 Dec 2018 07:27:50 +0000 (09:27 +0200)
committerGitHub <noreply@github.com>
Tue, 11 Dec 2018 07:27:50 +0000 (09:27 +0200)
(cherry picked from commit 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6)

Modules/_elementtree.c
Modules/_threadmodule.c
Modules/socketmodule.c
Objects/namespaceobject.c
Python/_warnings.c
Python/ceval.c
Python/codecs.c
Python/import.c
Python/pylifecycle.c

index 5c6959662316f5ee8a92a1ab48e8aab2b1522e63..30e382dd6c5eed307a03c911bfcfb6c3fdde139f 100644 (file)
@@ -352,7 +352,10 @@ get_attrib_from_keywords(PyObject *kwds)
             return NULL;
         }
         attrib = PyDict_Copy(attrib);
-        PyDict_DelItem(kwds, attrib_str);
+        if (attrib && PyDict_DelItem(kwds, attrib_str) < 0) {
+            Py_DECREF(attrib);
+            attrib = NULL;
+        }
     } else {
         attrib = PyDict_New();
     }
index c504b57b064f3bca1905fc6825c202ef6a77224f..a13b2e07400cca728bf0c6c46d95a3df7f042378 100644 (file)
@@ -785,9 +785,11 @@ local_clear(localobject *self)
         for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
             tstate;
             tstate = PyThreadState_Next(tstate))
-            if (tstate->dict &&
-                PyDict_GetItem(tstate->dict, self->key))
-                PyDict_DelItem(tstate->dict, self->key);
+            if (tstate->dict && PyDict_GetItem(tstate->dict, self->key)) {
+                if (PyDict_DelItem(tstate->dict, self->key)) {
+                    PyErr_Clear();
+                }
+            }
     }
     return 0;
 }
index 0daf98b6d23853664857313ae8ea65efac775911..520867458c1b8919a8a5901c56675b31018b5e94 100644 (file)
@@ -367,10 +367,14 @@ remove_unusable_flags(PyObject *m)
         else {
             if (PyDict_GetItemString(
                     dict,
-                    win_runtime_flags[i].flag_name) != NULL) {
-                PyDict_DelItemString(
-                    dict,
-                    win_runtime_flags[i].flag_name);
+                    win_runtime_flags[i].flag_name) != NULL)
+            {
+                if (PyDict_DelItemString(
+                        dict,
+                        win_runtime_flags[i].flag_name))
+                {
+                    PyErr_Clear();
+                }
             }
         }
     }
index 6307ee0423dc299e6a65e460b4ce24eea97547d2..a810effeb3d39e03cfed68221e6b780192fc93c3 100644 (file)
@@ -109,15 +109,15 @@ namespace_repr(PyObject *ns)
             PyObject *value, *item;
 
             value = PyDict_GetItem(d, key);
-            assert(value != NULL);
-
-            item = PyUnicode_FromFormat("%S=%R", key, value);
-            if (item == NULL) {
-                loop_error = 1;
-            }
-            else {
-                loop_error = PyList_Append(pairs, item);
-                Py_DECREF(item);
+            if (value != NULL) {
+                item = PyUnicode_FromFormat("%S=%R", key, value);
+                if (item == NULL) {
+                    loop_error = 1;
+                }
+                else {
+                    loop_error = PyList_Append(pairs, item);
+                    Py_DECREF(item);
+                }
             }
         }
 
index e96e154b0d542faf6e941bc4d83aae7822f6ef60..3ae68bb2613b61a76b61fd1b3aa841d997a8189b 100644 (file)
@@ -248,7 +248,11 @@ already_warned(PyObject *registry, PyObject *key, int should_set)
     version_obj = _PyDict_GetItemId(registry, &PyId_version);
     if (version_obj == NULL
         || !PyLong_CheckExact(version_obj)
-        || PyLong_AsLong(version_obj) != _filters_version) {
+        || PyLong_AsLong(version_obj) != _filters_version)
+    {
+        if (PyErr_Occurred()) {
+            return -1;
+        }
         PyDict_Clear(registry);
         version_obj = PyLong_FromLong(_filters_version);
         if (version_obj == NULL)
index 38d1d73845fbdaba79eb6b17e0de6f27fff2bbd5..36e966470dba54841b8cfe7877b5dfd6f9acfbc1 100644 (file)
@@ -5471,7 +5471,7 @@ unicode_concatenate(PyObject *v, PyObject *w,
             PyObject *names = f->f_code->co_names;
             PyObject *name = GETITEM(names, oparg);
             PyObject *locals = f->f_locals;
-            if (PyDict_CheckExact(locals) &&
+            if (locals && PyDict_CheckExact(locals) &&
                 PyDict_GetItem(locals, name) == v) {
                 if (PyDict_DelItem(locals, name) != 0) {
                     PyErr_Clear();
index 4ff83014d8bc82f091c780bb7eac9b88fbac3f28..584c1ef430deb59676942ad1ed780bdea61e0439 100644 (file)
@@ -129,8 +129,10 @@ PyObject *_PyCodec_Lookup(const char *encoding)
 
     /* Next, scan the search functions in order of registration */
     args = PyTuple_New(1);
-    if (args == NULL)
-        goto onError;
+    if (args == NULL) {
+        Py_DECREF(v);
+        return NULL;
+    }
     PyTuple_SET_ITEM(args,0,v);
 
     len = PyList_Size(interp->codec_search_path);
index db1650a9ddd2ea88ef7de45c43204599788f06f0..cb19270455825226473ab69e0a5587e0e0951a8f 100644 (file)
@@ -1973,10 +1973,10 @@ _imp_create_dynamic_impl(PyObject *module, PyObject *spec, PyObject *file)
     }
 
     mod = _PyImport_FindExtensionObject(name, path);
-    if (mod != NULL) {
+    if (mod != NULL || PyErr_Occurred()) {
         Py_DECREF(name);
         Py_DECREF(path);
-        Py_INCREF(mod);
+        Py_XINCREF(mod);
         return mod;
     }
 
index 56f04afc7701429e6b4a1196f255c213a6aab5da..0ebf9c702928e1ce5aa989810d2864dc0a90f05b 100644 (file)
@@ -797,6 +797,9 @@ Py_NewInterpreter(void)
             goto handle_error;
         Py_INCREF(interp->builtins);
     }
+    else if (PyErr_Occurred()) {
+        goto handle_error;
+    }
 
     /* initialize builtin exceptions */
     _PyExc_Init(bimod);