diff options
author | Victor Stinner <vstinner@wyplay.com> | 2013-07-17 11:41:39 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@wyplay.com> | 2013-07-17 11:41:39 (GMT) |
commit | 9a146eeadbf7e8a5f93e3ee817364928dba4613b (patch) | |
tree | 56f54cee5053bba7e6bdd14d1e1e44f08b885191 /Objects | |
parent | e5553142d452cf6c0a1e525d86fc60c5fbec0c04 (diff) | |
download | cpython-9a146eeadbf7e8a5f93e3ee817364928dba4613b.zip cpython-9a146eeadbf7e8a5f93e3ee817364928dba4613b.tar.gz cpython-9a146eeadbf7e8a5f93e3ee817364928dba4613b.tar.bz2 |
Issue #18408: Fix structseq_reduce(), handle PyDict_SetItemString() failure
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/structseq.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/Objects/structseq.c b/Objects/structseq.c index 212ab52..5553267 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -233,8 +233,8 @@ structseq_repr(PyStructSequence *obj) static PyObject * structseq_reduce(PyStructSequence* self) { - PyObject* tup; - PyObject* dict; + PyObject* tup = NULL; + PyObject* dict = NULL; PyObject* result; Py_ssize_t n_fields, n_visible_fields, n_unnamed_fields; int i; @@ -243,15 +243,12 @@ structseq_reduce(PyStructSequence* self) n_visible_fields = VISIBLE_SIZE(self); n_unnamed_fields = UNNAMED_FIELDS(self); tup = PyTuple_New(n_visible_fields); - if (!tup) { - return NULL; - } + if (!tup) + goto error; dict = PyDict_New(); - if (!dict) { - Py_DECREF(tup); - return NULL; - } + if (!dict) + goto error; for (i = 0; i < n_visible_fields; i++) { Py_INCREF(self->ob_item[i]); @@ -260,8 +257,8 @@ structseq_reduce(PyStructSequence* self) for (; i < n_fields; i++) { char *n = Py_TYPE(self)->tp_members[i-n_unnamed_fields].name; - PyDict_SetItemString(dict, n, - self->ob_item[i]); + if (PyDict_SetItemString(dict, n, self->ob_item[i]) < 0) + goto error; } result = Py_BuildValue("(O(OO))", Py_TYPE(self), tup, dict); @@ -270,6 +267,11 @@ structseq_reduce(PyStructSequence* self) Py_DECREF(dict); return result; + +error: + Py_XDECREF(tup); + Py_XDECREF(dict); + return NULL; } static PyMethodDef structseq_methods[] = { |