Commit d1e0ef68 authored by Neal Norwitz's avatar Neal Norwitz

SF #1445431, fix some leaks in error conditions.

parent c3264e50
...@@ -657,9 +657,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num) ...@@ -657,9 +657,10 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
} }
} }
if (!ok) { if (!ok) {
PyErr_SetObject(parser_error, PyObject *err = Py_BuildValue("os", elem,
Py_BuildValue("os", elem, "Illegal node construct.");
"Illegal node construct.")); PyErr_SetObject(parser_error, err);
Py_XDECREF(err);
Py_XDECREF(elem); Py_XDECREF(elem);
return (0); return (0);
} }
...@@ -710,8 +711,9 @@ build_node_children(PyObject *tuple, node *root, int *line_num) ...@@ -710,8 +711,9 @@ build_node_children(PyObject *tuple, node *root, int *line_num)
* It has to be one or the other; this is an error. * It has to be one or the other; this is an error.
* Throw an exception. * Throw an exception.
*/ */
PyErr_SetObject(parser_error, PyObject *err = Py_BuildValue("os", elem, "unknown node type.");
Py_BuildValue("os", elem, "unknown node type.")); PyErr_SetObject(parser_error, err);
Py_XDECREF(err);
Py_XDECREF(elem); Py_XDECREF(elem);
return (0); return (0);
} }
...@@ -762,6 +764,7 @@ build_node_tree(PyObject *tuple) ...@@ -762,6 +764,7 @@ build_node_tree(PyObject *tuple)
tuple = Py_BuildValue("os", tuple, tuple = Py_BuildValue("os", tuple,
"Illegal syntax-tree; cannot start with terminal symbol."); "Illegal syntax-tree; cannot start with terminal symbol.");
PyErr_SetObject(parser_error, tuple); PyErr_SetObject(parser_error, tuple);
Py_XDECREF(tuple);
} }
else if (ISNONTERMINAL(num)) { else if (ISNONTERMINAL(num)) {
/* /*
...@@ -792,14 +795,16 @@ build_node_tree(PyObject *tuple) ...@@ -792,14 +795,16 @@ build_node_tree(PyObject *tuple)
} }
} }
} }
else else {
/* The tuple is illegal -- if the number is neither TERMINAL nor /* The tuple is illegal -- if the number is neither TERMINAL nor
* NONTERMINAL, we can't use it. Not sure the implementation * NONTERMINAL, we can't use it. Not sure the implementation
* allows this condition, but the API doesn't preclude it. * allows this condition, but the API doesn't preclude it.
*/ */
PyErr_SetObject(parser_error, PyObject *err = Py_BuildValue("os", tuple,
Py_BuildValue("os", tuple, "Illegal component tuple.");
"Illegal component tuple.")); PyErr_SetObject(parser_error, err);
Py_XDECREF(err);
}
return (res); return (res);
} }
......
...@@ -6396,14 +6396,15 @@ posix_tmpnam(PyObject *self, PyObject *noargs) ...@@ -6396,14 +6396,15 @@ posix_tmpnam(PyObject *self, PyObject *noargs)
name = tmpnam(buffer); name = tmpnam(buffer);
#endif #endif
if (name == NULL) { if (name == NULL) {
PyErr_SetObject(PyExc_OSError, PyObject *err = Py_BuildValue("is", 0,
Py_BuildValue("is", 0,
#ifdef USE_TMPNAM_R #ifdef USE_TMPNAM_R
"unexpected NULL from tmpnam_r" "unexpected NULL from tmpnam_r"
#else #else
"unexpected NULL from tmpnam" "unexpected NULL from tmpnam"
#endif #endif
)); );
PyErr_SetObject(PyExc_OSError, err);
Py_XDECREF(err);
return NULL; return NULL;
} }
return PyString_FromString(buffer); return PyString_FromString(buffer);
......
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