Hackers, most places that use SPI_connect ... SPI_finish check the return value of SPI_finish and elog if it failed. There are a few places that do not, and it is unclear to me why this is safe. SPI_finish appears to be needed to clean up memory contexts.
Examples can be found in: src/backend/utils/adt/xml.c src/backend/utils/adt/tsvector_op.c src/backend/utils/adt/tsquery_rewrite.c src/test/regress/regress.c contrib/spi/refint.c The return value of SPI_execute is ignored in one spot: src/backend/utils/adt/xml.c circa line 2465. I checked the archives and did not see any discussion about this in the past. Please excuse me if this has been asked before.