summaryrefslogtreecommitdiff
path: root/src/pl/plpython/plpy_resultobject.c
diff options
context:
space:
mode:
authorPeter Eisentraut2017-10-31 14:49:36 +0000
committerPeter Eisentraut2017-11-18 18:39:53 +0000
commitd0aa965c0a0ac2ff7906ae1b1dad50a7952efa56 (patch)
tree0a464efb705e7df59aefb68bb7cbcba3772fb9fa /src/pl/plpython/plpy_resultobject.c
parent976a1a48fc35cde3c750982be64f872c4de4d343 (diff)
Consistently catch errors from Python _New() functions
Python Py*_New() functions can fail and return NULL in out-of-memory conditions. The previous code handled that inconsistently or not at all. This change organizes that better. If we are in a function that is called from Python, we just check for failure and return NULL ourselves, which will cause any exception information to be passed up. If we are called from PostgreSQL, we consistently create an "out of memory" error. Reviewed-by: Tom Lane <[email protected]>
Diffstat (limited to 'src/pl/plpython/plpy_resultobject.c')
-rw-r--r--src/pl/plpython/plpy_resultobject.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/pl/plpython/plpy_resultobject.c b/src/pl/plpython/plpy_resultobject.c
index 098a366f6fa..ca70e256892 100644
--- a/src/pl/plpython/plpy_resultobject.c
+++ b/src/pl/plpython/plpy_resultobject.c
@@ -112,6 +112,11 @@ PLy_result_new(void)
ob->nrows = PyInt_FromLong(-1);
ob->rows = PyList_New(0);
ob->tupdesc = NULL;
+ if (!ob->rows)
+ {
+ Py_DECREF(ob);
+ return NULL;
+ }
return (PyObject *) ob;
}
@@ -147,6 +152,8 @@ PLy_result_colnames(PyObject *self, PyObject *unused)
}
list = PyList_New(ob->tupdesc->natts);
+ if (!list)
+ return NULL;
for (i = 0; i < ob->tupdesc->natts; i++)
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
@@ -171,6 +178,8 @@ PLy_result_coltypes(PyObject *self, PyObject *unused)
}
list = PyList_New(ob->tupdesc->natts);
+ if (!list)
+ return NULL;
for (i = 0; i < ob->tupdesc->natts; i++)
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);
@@ -195,6 +204,8 @@ PLy_result_coltypmods(PyObject *self, PyObject *unused)
}
list = PyList_New(ob->tupdesc->natts);
+ if (!list)
+ return NULL;
for (i = 0; i < ob->tupdesc->natts; i++)
{
Form_pg_attribute attr = TupleDescAttr(ob->tupdesc, i);