summaryrefslogtreecommitdiff
path: root/contrib/ltree_plpython
diff options
context:
space:
mode:
authorPeter Eisentraut2017-10-31 14:49:36 +0000
committerPeter Eisentraut2017-11-18 18:39:53 +0000
commitd0aa965c0a0ac2ff7906ae1b1dad50a7952efa56 (patch)
tree0a464efb705e7df59aefb68bb7cbcba3772fb9fa /contrib/ltree_plpython
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 <tgl@sss.pgh.pa.us>
Diffstat (limited to 'contrib/ltree_plpython')
-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++)