Commit e42e2f38 authored by Peter Eisentraut's avatar Peter Eisentraut

PL/Python: Fix potential NULL pointer dereference

After d0aa965c, one error path in
PLy_spi_execute_fetch_result() could result in the variable "result"
being dereferenced after being set to NULL.  To fix that, just clear the
resources right there and return early.

Also add another SPI_freetuptable() call so that that is cleared in all
error paths.

discovered by John Naylor <jcnaylor@gmail.com> via scan-build
parent 7b88d63a
......@@ -361,7 +361,10 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
result = (PLyResultObject *) PLy_result_new();
if (!result)
{
SPI_freetuptable(tuptable);
return NULL;
}
Py_DECREF(result->status);
result->status = PyInt_FromLong(status);
......@@ -414,7 +417,9 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
if (!result->rows)
{
Py_DECREF(result);
result = NULL;
MemoryContextDelete(cxt);
SPI_freetuptable(tuptable);
return NULL;
}
else
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment