|
3 | 3 | * procedural language (PL)
|
4 | 4 | *
|
5 | 5 | * IDENTIFICATION
|
6 |
| - * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.6 1998/09/01 04:40:28 momjian Exp $ |
| 6 | + * $Header: /cvsroot/pgsql/src/pl/tcl/pltcl.c,v 1.7 1998/10/09 16:57:10 momjian Exp $ |
7 | 7 | *
|
8 | 8 | * This software is copyrighted by Jan Wieck - Hamburg.
|
9 | 9 | *
|
@@ -417,12 +417,6 @@ pltcl_call_handler(FmgrInfo *proinfo,
|
417 | 417 |
|
418 | 418 | pltcl_call_level--;
|
419 | 419 |
|
420 |
| - /************************************************************ |
421 |
| - * Disconnect from SPI manager |
422 |
| - ************************************************************/ |
423 |
| - if (SPI_finish() != SPI_OK_FINISH) |
424 |
| - elog(ERROR, "pltcl: SPI_finish() failed"); |
425 |
| - |
426 | 420 | return retval;
|
427 | 421 | }
|
428 | 422 |
|
@@ -731,6 +725,15 @@ pltcl_func_handler(FmgrInfo *proinfo,
|
731 | 725 | siglongjmp(Warn_restart, 1);
|
732 | 726 | }
|
733 | 727 |
|
| 728 | + /************************************************************ |
| 729 | + * Disconnect from SPI manager and then create the return |
| 730 | + * values datum (if the input function does a palloc for it |
| 731 | + * this must not be allocated in the SPI memory context |
| 732 | + * because SPI_finish would free it). |
| 733 | + ************************************************************/ |
| 734 | + if (SPI_finish() != SPI_OK_FINISH) |
| 735 | + elog(ERROR, "pltcl: SPI_finish() failed"); |
| 736 | + |
734 | 737 | retval = (Datum) (*fmgr_faddr(&prodesc->result_in_func))
|
735 | 738 | (pltcl_safe_interp->result,
|
736 | 739 | prodesc->result_in_elem,
|
@@ -1051,8 +1054,12 @@ pltcl_trigger_handler(FmgrInfo *proinfo)
|
1051 | 1054 | * The return value from the procedure might be one of
|
1052 | 1055 | * the magic strings OK or SKIP or a list from array get
|
1053 | 1056 | ************************************************************/
|
1054 |
| - if (strcmp(pltcl_safe_interp->result, "OK") == 0) |
| 1057 | + if (SPI_finish() != SPI_OK_FINISH) |
| 1058 | + elog(ERROR, "pltcl: SPI_finish() failed"); |
| 1059 | + |
| 1060 | + if (strcmp(pltcl_safe_interp->result, "OK") == 0) { |
1055 | 1061 | return rettup;
|
| 1062 | + } |
1056 | 1063 | if (strcmp(pltcl_safe_interp->result, "SKIP") == 0)
|
1057 | 1064 | {
|
1058 | 1065 | return (HeapTuple) NULL;;
|
@@ -1309,7 +1316,7 @@ pltcl_SPI_exec(ClientData cdata, Tcl_Interp * interp,
|
1309 | 1316 | int loop_rc;
|
1310 | 1317 | int ntuples;
|
1311 | 1318 | HeapTuple *tuples;
|
1312 |
| - TupleDesc tupdesc; |
| 1319 | + TupleDesc tupdesc = NULL; |
1313 | 1320 | sigjmp_buf save_restart;
|
1314 | 1321 |
|
1315 | 1322 | char *usage = "syntax error - 'SPI_exec "
|
|
0 commit comments