aboutsummaryrefslogtreecommitdiff
path: root/contrib/ltree_plpython/ltree_plpython.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2017-10-31 10:49:36 -0400
committerPeter Eisentraut <peter_e@gmx.net>2017-11-18 13:39:53 -0500
commitd0aa965c0a0ac2ff7906ae1b1dad50a7952efa56 (patch)
tree0a464efb705e7df59aefb68bb7cbcba3772fb9fa /contrib/ltree_plpython/ltree_plpython.c
parent976a1a48fc35cde3c750982be64f872c4de4d343 (diff)
downloadpostgresql-d0aa965c0a0ac2ff7906ae1b1dad50a7952efa56.tar.gz
postgresql-d0aa965c0a0ac2ff7906ae1b1dad50a7952efa56.zip
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 <tgl@sss.pgh.pa.us>
Diffstat (limited to 'contrib/ltree_plpython/ltree_plpython.c')
-rw-r--r--contrib/ltree_plpython/ltree_plpython.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/contrib/ltree_plpython/ltree_plpython.c b/contrib/ltree_plpython/ltree_plpython.c
index ae9b90dd10b..e88636a0a96 100644
--- a/contrib/ltree_plpython/ltree_plpython.c
+++ b/contrib/ltree_plpython/ltree_plpython.c
@@ -46,6 +46,10 @@ ltree_to_plpython(PG_FUNCTION_ARGS)
ltree_level *curlevel;
list = PyList_New(in->numlevel);
+ if (!list)
+ ereport(ERROR,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
curlevel = LTREE_FIRST(in);
for (i = 0; i < in->numlevel; i++)