mirror of
https://github.com/postgres/postgres.git
synced 2025-06-13 07:41:39 +03:00
PL/Python: Fix potential NULL pointer dereference
After d0aa965c0a
, 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
This commit is contained in:
@ -361,7 +361,10 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
|
|||||||
|
|
||||||
result = (PLyResultObject *) PLy_result_new();
|
result = (PLyResultObject *) PLy_result_new();
|
||||||
if (!result)
|
if (!result)
|
||||||
|
{
|
||||||
|
SPI_freetuptable(tuptable);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
Py_DECREF(result->status);
|
Py_DECREF(result->status);
|
||||||
result->status = PyInt_FromLong(status);
|
result->status = PyInt_FromLong(status);
|
||||||
|
|
||||||
@ -414,7 +417,9 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, uint64 rows, int status)
|
|||||||
if (!result->rows)
|
if (!result->rows)
|
||||||
{
|
{
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
result = NULL;
|
MemoryContextDelete(cxt);
|
||||||
|
SPI_freetuptable(tuptable);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user