Commit 80d50428 authored by Benjamin Peterson's avatar Benjamin Peterson

fix parse_syntax_error to clean up its resources

parent 6215444a
...@@ -1335,56 +1335,67 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename, ...@@ -1335,56 +1335,67 @@ parse_syntax_error(PyObject *err, PyObject **message, const char **filename,
return PyArg_ParseTuple(err, "O(ziiz)", message, filename, return PyArg_ParseTuple(err, "O(ziiz)", message, filename,
lineno, offset, text); 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; goto finally;
*message = v;
if (!(v = PyObject_GetAttrString(err, "filename"))) v = PyObject_GetAttrString(err, "filename");
if (!v)
goto finally; goto finally;
if (v == Py_None) if (v == Py_None) {
Py_DECREF(v);
*filename = NULL; *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); v = PyObject_GetAttrString(err, "lineno");
if (!(v = PyObject_GetAttrString(err, "lineno"))) if (!v)
goto finally; goto finally;
hold = PyLong_AsLong(v); hold = PyLong_AsLong(v);
Py_DECREF(v); Py_DECREF(v);
v = NULL;
if (hold < 0 && PyErr_Occurred()) if (hold < 0 && PyErr_Occurred())
goto finally; goto finally;
*lineno = (int)hold; *lineno = (int)hold;
if (!(v = PyObject_GetAttrString(err, "offset"))) v = PyObject_GetAttrString(err, "offset");
if (!v)
goto finally; goto finally;
if (v == Py_None) { if (v == Py_None) {
*offset = -1; *offset = -1;
Py_DECREF(v); Py_DECREF(v);
v = NULL;
} else { } else {
hold = PyLong_AsLong(v); hold = PyLong_AsLong(v);
Py_DECREF(v); Py_DECREF(v);
v = NULL;
if (hold < 0 && PyErr_Occurred()) if (hold < 0 && PyErr_Occurred())
goto finally; goto finally;
*offset = (int)hold; *offset = (int)hold;
} }
if (!(v = PyObject_GetAttrString(err, "text"))) v = PyObject_GetAttrString(err, "text");
if (!v)
goto finally; goto finally;
if (v == Py_None) if (v == Py_None) {
Py_DECREF(v);
*text = NULL; *text = NULL;
else if (!PyUnicode_Check(v) || }
!(*text = _PyUnicode_AsString(v))) else {
goto finally; *text = _PyUnicode_AsString(v);
Py_DECREF(v); Py_DECREF(v);
if (!*text)
goto finally;
}
return 1; return 1;
finally: finally:
Py_XDECREF(v); Py_XDECREF(*message);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment