diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-04-03 04:30:38 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-04-03 04:30:38 (GMT) |
commit | 80d50428ce7697cc2f1fdb4370800b89399c4cda (patch) | |
tree | d0785a6c2c3cc3ed03a0625874389f9934c7f6fd /Python | |
parent | 6215444a0a35cca9c3893e319d309de102d47f28 (diff) | |
download | cpython-80d50428ce7697cc2f1fdb4370800b89399c4cda.zip cpython-80d50428ce7697cc2f1fdb4370800b89399c4cda.tar.gz cpython-80d50428ce7697cc2f1fdb4370800b89399c4cda.tar.bz2 |
fix parse_syntax_error to clean up its resources
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pythonrun.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c index 584a19b..5a96bae 100644 --- a/Python/pythonrun.c +++ b/Python/pythonrun.c @@ -1335,56 +1335,67 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, return PyArg_ParseTuple(err, "O(ziiz)", message, filename, lineno, offset, text); - /* new style errors. `err' is an instance */ + *message = NULL; - if (! (v = PyObject_GetAttrString(err, "msg"))) + /* new style errors. `err' is an instance */ + *message = PyObject_GetAttrString(err, "msg"); + if (!*message) goto finally; - *message = v; - if (!(v = PyObject_GetAttrString(err, "filename"))) + v = PyObject_GetAttrString(err, "filename"); + if (!v) goto finally; - if (v == Py_None) + if (v == Py_None) { + Py_DECREF(v); *filename = NULL; - else if (! (*filename = _PyUnicode_AsString(v))) - goto finally; + } + else { + *filename = _PyUnicode_AsString(v); + Py_DECREF(v); + if (!*filename) + goto finally; + } - Py_DECREF(v); - if (!(v = PyObject_GetAttrString(err, "lineno"))) + v = PyObject_GetAttrString(err, "lineno"); + if (!v) goto finally; hold = PyLong_AsLong(v); Py_DECREF(v); - v = NULL; if (hold < 0 && PyErr_Occurred()) goto finally; *lineno = (int)hold; - if (!(v = PyObject_GetAttrString(err, "offset"))) + v = PyObject_GetAttrString(err, "offset"); + if (!v) goto finally; if (v == Py_None) { *offset = -1; Py_DECREF(v); - v = NULL; } else { hold = PyLong_AsLong(v); Py_DECREF(v); - v = NULL; if (hold < 0 && PyErr_Occurred()) goto finally; *offset = (int)hold; } - if (!(v = PyObject_GetAttrString(err, "text"))) + v = PyObject_GetAttrString(err, "text"); + if (!v) goto finally; - if (v == Py_None) + if (v == Py_None) { + Py_DECREF(v); *text = NULL; - else if (!PyUnicode_Check(v) || - !(*text = _PyUnicode_AsString(v))) - goto finally; - Py_DECREF(v); + } + else { + *text = _PyUnicode_AsString(v); + Py_DECREF(v); + if (!*text) + goto finally; + } return 1; finally: - Py_XDECREF(v); + Py_XDECREF(*message); return 0; } |