Skip to content

Commit 88dcdf9

Browse files
committed
Call PLy_spi_execute_fetch_result inside the try/catch block
This way errors from fetching tuples are correctly reported as errors in the SPI call. While at it, avoid palloc(0). Jan Urbański
1 parent 52713d0 commit 88dcdf9

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/pl/plpython/plpython.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2978,6 +2978,7 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit)
29782978
rv;
29792979
PLyPlanObject *plan;
29802980
volatile MemoryContext oldcontext;
2981+
PyObject *ret;
29812982

29822983
if (list != NULL)
29832984
{
@@ -3014,9 +3015,14 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit)
30143015
oldcontext = CurrentMemoryContext;
30153016
PG_TRY();
30163017
{
3017-
char *nulls = palloc(nargs * sizeof(char));
3018+
char *nulls;
30183019
volatile int j;
30193020

3021+
if (nargs > 0)
3022+
nulls = palloc(nargs * sizeof(char));
3023+
else
3024+
nulls = NULL;
3025+
30203026
for (j = 0; j < nargs; j++)
30213027
{
30223028
PyObject *elem;
@@ -3055,8 +3061,10 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit)
30553061

30563062
rv = SPI_execute_plan(plan->plan, plan->values, nulls,
30573063
PLy_curr_procedure->fn_readonly, limit);
3064+
ret = PLy_spi_execute_fetch_result(SPI_tuptable, SPI_processed, rv);
30583065

3059-
pfree(nulls);
3066+
if (nargs > 0)
3067+
pfree(nulls);
30603068
}
30613069
PG_CATCH();
30623070
{
@@ -3099,20 +3107,22 @@ PLy_spi_execute_plan(PyObject *ob, PyObject *list, long limit)
30993107
}
31003108
}
31013109

3102-
return PLy_spi_execute_fetch_result(SPI_tuptable, SPI_processed, rv);
3110+
return ret;
31033111
}
31043112

31053113
static PyObject *
31063114
PLy_spi_execute_query(char *query, long limit)
31073115
{
31083116
int rv;
31093117
volatile MemoryContext oldcontext;
3118+
PyObject *ret;
31103119

31113120
oldcontext = CurrentMemoryContext;
31123121
PG_TRY();
31133122
{
31143123
pg_verifymbstr(query, strlen(query), false);
31153124
rv = SPI_execute(query, PLy_curr_procedure->fn_readonly, limit);
3125+
ret = PLy_spi_execute_fetch_result(SPI_tuptable, SPI_processed, rv);
31163126
}
31173127
PG_CATCH();
31183128
{
@@ -3138,7 +3148,7 @@ PLy_spi_execute_query(char *query, long limit)
31383148
return NULL;
31393149
}
31403150

3141-
return PLy_spi_execute_fetch_result(SPI_tuptable, SPI_processed, rv);
3151+
return ret;
31423152
}
31433153

31443154
static PyObject *

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy