diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2018-12-11 07:27:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-11 07:27:50 (GMT) |
commit | 8855d9339858683c9b4fcd50b02a7bca526d4726 (patch) | |
tree | 3c85fc696f92556807f1031f9653ed3b73d70561 | |
parent | 37607f26697351751165a042f91f04530ce333f7 (diff) | |
download | cpython-8855d9339858683c9b4fcd50b02a7bca526d4726.zip cpython-8855d9339858683c9b4fcd50b02a7bca526d4726.tar.gz cpython-8855d9339858683c9b4fcd50b02a7bca526d4726.tar.bz2 |
[3.6] bpo-35454: Fix miscellaneous minor issues in error handling. (GH-11077) (GH-11106)
(cherry picked from commit 8905fcc85a6fc3ac394bc89b0bbf40897e9497a6)
-rw-r--r-- | Modules/_elementtree.c | 5 | ||||
-rw-r--r-- | Modules/_threadmodule.c | 8 | ||||
-rw-r--r-- | Modules/socketmodule.c | 12 | ||||
-rw-r--r-- | Objects/namespaceobject.c | 18 | ||||
-rw-r--r-- | Python/_warnings.c | 6 | ||||
-rw-r--r-- | Python/ceval.c | 2 | ||||
-rw-r--r-- | Python/codecs.c | 6 | ||||
-rw-r--r-- | Python/import.c | 4 | ||||
-rw-r--r-- | Python/pylifecycle.c | 3 |
9 files changed, 41 insertions, 23 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index 5c69596..30e382d 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -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(); } diff --git a/Modules/_threadmodule.c b/Modules/_threadmodule.c index c504b57..a13b2e0 100644 --- a/Modules/_threadmodule.c +++ b/Modules/_threadmodule.c @@ -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; } diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 0daf98b..5208674 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -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(); + } } } } diff --git a/Objects/namespaceobject.c b/Objects/namespaceobject.c index 6307ee0..a810eff 100644 --- a/Objects/namespaceobject.c +++ b/Objects/namespaceobject.c @@ -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); + } } } diff --git a/Python/_warnings.c b/Python/_warnings.c index e96e154..3ae68bb 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -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) diff --git a/Python/ceval.c b/Python/ceval.c index 38d1d73..36e9664 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -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(); diff --git a/Python/codecs.c b/Python/codecs.c index 4ff8301..584c1ef 100644 --- a/Python/codecs.c +++ b/Python/codecs.c @@ -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); diff --git a/Python/import.c b/Python/import.c index db1650a..cb19270 100644 --- a/Python/import.c +++ b/Python/import.c @@ -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; } diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index 56f04af..0ebf9c7 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -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); |