Py_INCREF(mainmod);
PLy_interp_globals = PyModule_GetDict(mainmod);
PLy_interp_safe_globals = PyDict_New();
+ if (PLy_interp_safe_globals == NULL)
+ PLy_elog(ERROR, "could not create globals");
PyDict_SetItemString(PLy_interp_globals, "GD", PLy_interp_safe_globals);
Py_DECREF(mainmod);
if (PLy_interp_globals == NULL || PyErr_Occurred())
main_mod = PyImport_AddModule("__main__");
main_dict = PyModule_GetDict(main_mod);
plpy_mod = PyImport_AddModule("plpy");
+ if (plpy_mod == NULL)
+ PLy_elog(ERROR, "could not initialize plpy");
PyDict_SetItemString(main_dict, "plpy", plpy_mod);
if (PyErr_Occurred())
- elog(ERROR, "could not initialize plpy");
+ PLy_elog(ERROR, "could not initialize plpy");
}
static void
PLy_exc_fatal = PyErr_NewException("plpy.Fatal", NULL, NULL);
PLy_exc_spi_error = PyErr_NewException("plpy.SPIError", NULL, NULL);
+ if (PLy_exc_error == NULL ||
+ PLy_exc_fatal == NULL ||
+ PLy_exc_spi_error == NULL)
+ PLy_elog(ERROR, "could not create the base SPI exceptions");
+
Py_INCREF(PLy_exc_error);
PyModule_AddObject(plpy, "Error", PLy_exc_error);
Py_INCREF(PLy_exc_fatal);
PyObject *sqlstate;
PyObject *dict = PyDict_New();
+ if (dict == NULL)
+ PLy_elog(ERROR, "could not generate SPI exceptions");
+
sqlstate = PyString_FromString(unpack_sql_state(exception_map[i].sqlstate));
+ if (sqlstate == NULL)
+ PLy_elog(ERROR, "could not generate SPI exceptions");
+
PyDict_SetItemString(dict, "sqlstate", sqlstate);
Py_DECREF(sqlstate);
exc = PyErr_NewException(exception_map[i].name, base, dict);
*/
PyObject *o;
- PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o);
+ if (!PyArg_UnpackTuple(args, "plpy.elog", 1, 1, &o))
+ PLy_elog(ERROR, "could not unpack arguments in plpy.elog");
so = PyObject_Str(o);
}
else
int rv;
volatile MemoryContext oldcontext;
volatile ResourceOwner oldowner;
- PyObject *ret;
+ PyObject *ret = NULL;
oldcontext = CurrentMemoryContext;
oldowner = CurrentResourceOwner;
if (rv < 0)
{
+ Py_XDECREF(ret);
PLy_exception_set(PLy_exc_spi_error,
"SPI_execute failed: %s",
SPI_result_code_string(rv));