Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3b10c3

Browse files
committed
Fix error handling in PLy_spi_execute_fetch_result().
If an error is thrown out of the datatype I/O functions called by thisfunction, we need to do subtransaction cleanup, which the previous codingentirely failed to do. Fortunately, both existing callers of this functionalready have proper cleanup logic, so re-throwing the exception is enough.Also, postpone creation of the resultset tupdesc until after the I/Oconversions are complete, so that we won't leak memory in TopMemoryContextwhen such an error happens.
1 parentff41a5d commitb3b10c3

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

‎src/pl/plpython/plpy_spi.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -407,16 +407,6 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
407407
{
408408
MemoryContextoldcontext2;
409409

410-
/*
411-
* Save tuple descriptor for later use by result set metadata
412-
* functions. Save it in TopMemoryContext so that it survives
413-
* outside of an SPI context. We trust that PLy_result_dealloc()
414-
* will clean it up when the time is right.
415-
*/
416-
oldcontext2=MemoryContextSwitchTo(TopMemoryContext);
417-
result->tupdesc=CreateTupleDescCopy(tuptable->tupdesc);
418-
MemoryContextSwitchTo(oldcontext2);
419-
420410
if (rows)
421411
{
422412
Py_DECREF(result->rows);
@@ -425,23 +415,33 @@ PLy_spi_execute_fetch_result(SPITupleTable *tuptable, int rows, int status)
425415
PLy_input_tuple_funcs(&args,tuptable->tupdesc);
426416
for (i=0;i<rows;i++)
427417
{
428-
PyObject*row=PLyDict_FromTuple(&args,tuptable->vals[i],
418+
PyObject*row=PLyDict_FromTuple(&args,
419+
tuptable->vals[i],
429420
tuptable->tupdesc);
430421

431422
PyList_SetItem(result->rows,i,row);
432423
}
433424
}
425+
426+
/*
427+
* Save tuple descriptor for later use by result set metadata
428+
* functions. Save it in TopMemoryContext so that it survives
429+
* outside of an SPI context. We trust that PLy_result_dealloc()
430+
* will clean it up when the time is right. (Do this as late as
431+
* possible, to minimize the number of ways the tupdesc could get
432+
* leaked due to errors.)
433+
*/
434+
oldcontext2=MemoryContextSwitchTo(TopMemoryContext);
435+
result->tupdesc=CreateTupleDescCopy(tuptable->tupdesc);
436+
MemoryContextSwitchTo(oldcontext2);
434437
}
435438
PG_CATCH();
436439
{
437440
MemoryContextSwitchTo(oldcontext);
438-
if (!PyErr_Occurred())
439-
PLy_exception_set(PLy_exc_error,
440-
"unrecognized error in PLy_spi_execute_fetch_result");
441441
PLy_typeinfo_dealloc(&args);
442442
SPI_freetuptable(tuptable);
443443
Py_DECREF(result);
444-
returnNULL;
444+
PG_RE_THROW();
445445
}
446446
PG_END_TRY();
447447

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp