[Python-checkins] r43151 - python/trunk/Modules/parsermodule.c python/trunk/Modules/posixmodule.c

neal.norwitz python-checkins at python.org
Mon Mar 20 05:08:16 CET 2006


Author: neal.norwitz
Date: Mon Mar 20 05:08:12 2006
New Revision: 43151
Modified:
 python/trunk/Modules/parsermodule.c
 python/trunk/Modules/posixmodule.c
Log:
SF #1445431, fix some leaks in error conditions.
Modified: python/trunk/Modules/parsermodule.c
==============================================================================
--- python/trunk/Modules/parsermodule.c	(original)
+++ python/trunk/Modules/parsermodule.c	Mon Mar 20 05:08:12 2006
@@ -657,9 +657,10 @@
 }
 }
 if (!ok) {
- PyErr_SetObject(parser_error,
- Py_BuildValue("os", elem,
- "Illegal node construct."));
+ PyObject *err = Py_BuildValue("os", elem,
+ "Illegal node construct.");
+ PyErr_SetObject(parser_error, err);
+ Py_XDECREF(err);
 Py_XDECREF(elem);
 return (0);
 }
@@ -710,8 +711,9 @@
 * It has to be one or the other; this is an error.
 * Throw an exception.
 */
- PyErr_SetObject(parser_error,
- Py_BuildValue("os", elem, "unknown node type."));
+ PyObject *err = Py_BuildValue("os", elem, "unknown node type.");
+ PyErr_SetObject(parser_error, err);
+ Py_XDECREF(err);
 Py_XDECREF(elem);
 return (0);
 }
@@ -762,6 +764,7 @@
 tuple = Py_BuildValue("os", tuple,
 "Illegal syntax-tree; cannot start with terminal symbol.");
 PyErr_SetObject(parser_error, tuple);
+ Py_XDECREF(tuple);
 }
 else if (ISNONTERMINAL(num)) {
 /*
@@ -792,14 +795,16 @@
 }
 }
 }
- else
+ else {
 /* The tuple is illegal -- if the number is neither TERMINAL nor
 * NONTERMINAL, we can't use it. Not sure the implementation
 * allows this condition, but the API doesn't preclude it.
 */
- PyErr_SetObject(parser_error,
- Py_BuildValue("os", tuple,
- "Illegal component tuple."));
+ PyObject *err = Py_BuildValue("os", tuple,
+ "Illegal component tuple.");
+ PyErr_SetObject(parser_error, err);
+ Py_XDECREF(err);
+ }
 
 return (res);
 }
Modified: python/trunk/Modules/posixmodule.c
==============================================================================
--- python/trunk/Modules/posixmodule.c	(original)
+++ python/trunk/Modules/posixmodule.c	Mon Mar 20 05:08:12 2006
@@ -6396,15 +6396,16 @@
 name = tmpnam(buffer);
 #endif
 if (name == NULL) {
- PyErr_SetObject(PyExc_OSError,
- Py_BuildValue("is", 0,
+	PyObject *err = Py_BuildValue("is", 0,
 #ifdef USE_TMPNAM_R
 "unexpected NULL from tmpnam_r"
 #else
 "unexpected NULL from tmpnam"
 #endif
- ));
- return NULL;
+ );
+	PyErr_SetObject(PyExc_OSError, err);
+	Py_XDECREF(err);
+	return NULL;
 }
 return PyString_FromString(buffer);
 }


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /